note 18376 deleted from ref.overload by sniper

From: Date: Thu, 06 Feb 2003 14:19:57 +0000
Subject: note 18376 deleted from ref.overload by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-43514@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 '=&'.

« previous php.notes (#43514) next »