このクラスを検討してください。
class test
{
public function __set($n, $v)
{
echo "__set() called\n";
$this->other_set($n, $v, true);
}
public function other_set($name, $value)
{
echo "other_set() called\n";
$this->$name = $value;
}
public function t()
{
$this->t = true;
}
}
PHPの魔法の__set()メソッドをオーバーロードしています。test クラスのオブジェクトにプロパティを設定すると、それは、を呼び出し__set()、次にはを呼び出しますother_set()。
$obj = new test;
$test->prop = 10;
/* prints the following */
__set() called
other_set() called
しかしother_set()、次の行があります$this->$name = $value。これにより、が呼び出され__set()、無限再帰が発生するのではないでしょうか。
__set()私はそれがクラスの外に物事を設定するときだけ呼び出すだろうと理論づけました。しかし、メソッドを呼び出すと、t()それも明確に通過していることがわかり__set()ます。