如果动态添加任何变量,类的大小是多少?
我们可以在 php.ini 中动态地将任何变量添加到类中。
动态添加对类的大小(内存)有何影响?
class test
{
public $a;
private $b;
function func1(){...}
}
$obj = new test();
$obj->c ="some value";
$obj 的大小是多少?
We can add any variable to class dynamically in php.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内存中对象的大小将取决于您要添加的变量的内容。菲利克斯实际上已经回答了这个问题,所以我只想使用他的回答:
prints
当然,当您使用更多数据时,您的脚本需要更多内存。但是,当您将该属性添加到类的实例时,它对类本身没有影响。
如果他决定取消删除他的答案,我会敦促你接受它,而不是我的:-)
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:
prints
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 :-)