<?php class MagicByRef { private $prop = 'hello'; private function &getProp($name) { printf( "%s: %s is %s\n", __METHOD__, $name, property_exists($this, $name) ? 'exists' : 'not exists' ); return $this->prop; } public function __set($name, $value) { echo __METHOD__ , "($name, $value)\n"; } public function &__get($name) { echo __METHOD__ , "($name)\n"; $this->$name = &$this->getProp($name); return $this->$name; } } echo 'Assignment by reference: $this->$name = &$this->getProp($name)', ":\n"; $m = new MagicByRef; $m->hello;
You have javascript disabled. You will not be able to edit any code.