【发布时间】:2013-12-31 04:42:20
【问题描述】:
我有以下场景:一个类,其方法在数组中存储键值并返回 void。
方法是这样的:
<?php
abstract class MyClass
{
// ...
protected function setAttribute($name, $value, $skipCasting = null)
{
// ...
$this->attributes[$name] =& $value;
}
// ...
}
现在,我在我的应用程序中多次使用此方法,其中 50% 的时间我只是设置属性,另外 50% 的时间我还需要返回我设置的值。
我想知道,就性能而言,如果我总是返回 something 会导致(显着)内存丢失?
【问题讨论】:
-
OOP 中通常的做法是返回 $this,这样你就可以链接 setter/其他函数
标签: php oop memory memory-leaks