What will be the size of class if any variable is added dynamically?
We can add any variable to class dynamically in php.
开发者_C百科What would be the effect on size(Memory) of class in dynamically addition?
class test
{
public $a;
private $b;
function func1(){...}
}
$obj = new test();
$obj->c ="some value";
What will be size of $obj?
The size of the object in memory is going to depend on the content of the variable you're adding. Felix actually answered this already so im just going to use his response:
$a = new C();
print memory_get_usage() . PHP_EOL;
$a->foo = "bar";
print memory_get_usage();
prints
43100
43308
Of course your script needs more memory as you are using more data. However, it has no effect on the class itself as you are adding the property to an instance of the class.
If He decides to undelete his answer i would urge you to accept it as opposed to mine :-)
精彩评论