note 34543 deleted from language.references by sniper

From: Date: Tue, 30 Sep 2003 01:19:26 +0000
Subject: note 34543 deleted from language.references by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57322@lists.php.net to get a copy of this message
Note Submitter: gooseFX ---- References under PHP is a real silly thing and i thought I had understood it but after call-time pass-by-reference has been deprecated I have several problems with them. For example I have a list object which stores ( as it says ) a list of objects or value types. Now I have a method add($var) which adds the value to the list. Before call-time pass-by-reference has been deprecated i just called the method like this: $myList->add( &$myVar ); This version of my list could handle object and value types. But now this feature has gone and I have to change my method argument to reference add(&$var), but this method does not take a value type like add(17), because only variables can be passed by reference. A big problem for my complete php library. What now??? My solution is a reference object which can be past by value but its internal reference will never get lost. class gfRef { var $ref = null; function gfRef(&$ref) { $this->ref =& $ref; $class_vars = get_class_vars(get_class($ref)); // create a reference to each variable foreach( $class_vars as $class_var => $class_value ) { $this->$class_var =& $ref->$class_var; } // copy all methods to the reference object aggregate_methods ( $this, get_class($ref)); } }; the reference object behave like the original object but each class variable is hold by reference. You can pass the ref object by value but it points to the original object and has the same methods and variables as the original one. This is just a suggestion but I think this is the best way to skip around php's object-by-value principle. Have any suggestion then mail to: marcus@gooseflesh.de

« previous php.notes (#57322) next »