note 18376 added to ref.overload

From: Date: Sun, 20 Jan 2002 18:33:04 +0000
Subject: note 18376 added to ref.overload
Groups: php.notes 
Request: Send a blank email to php-notes+get-25572@lists.php.net to get a copy of this message
I think that object references should be implicit when using objects. --- $my_object->child = $other_object; $foo = $my_object->child; $my_object->bar ( $other_object ); --- would be more interesting than --- $my_object->child =& $other_object; $foo =& $my_object->child; class MyClass { ... function bar ( &$object ) {...} ... }; --- __get, __set and __call will probably introduce a solution to this problem. class MyClass { /** * When accessing a class member, we return a reference * to the member if it's an object. Else, we return a * copy. */ function __get ($var_name, &$return) { if ( is_object($this->$var_name) ) { $return =& $this->$var_name; } else { $return = $this->$var_name; } return true; } /** * It seems that "__set()" does not take a reference to a * variable as second parameter (cf: overload() example). * But if &$value is possible, the following code should * work. */ function __set ($var_name, &$value ) { if ( is_object($value) ) { $this->$var_name =& $value; } else { $this->$var_name = $value; } return true; } }; overload ("MyClass"); The __call() method should also give a way to get parameters' references if they are objects. The problem : $foo = $my_object->foo; $foo is not a reference to $my_object->foo; If the right member of the '=' sign is a reference, it would be great if '=' do the same job as '=&'. -- http://www.php.net/manual/en/ref.overload.php http://master.php.net/manage/user-notes.php?action=edit+18376 http://master.php.net/manage/user-notes.php?action=delete+18376 http://master.php.net/manage/user-notes.php?action=reject+18376

« previous php.notes (#25572) next »