note 15384 added to function.eval

From: Date: Fri, 07 Sep 2001 16:36:10 +0000
Subject: note 15384 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-17776@lists.php.net to get a copy of this message
The similar way as shown in the above example you can access any object initialized at php script. For example if you want to use list of currently initialized objects in a class just do it this way: //somewhere in php code $o = new object_or_class; $o->id = 153; //now define class that works with objects defined in scripts using this class class Objects { function global_object ($object_name) { eval ("global \$$object_name;"); $newo = ${$object_name}; return $newo; } //and now access all object methods and variables like this: function foo { $object_name = "name of existing object" $ox = $this->global_object($object_name); echo $ox->id; } //this way it doesn't work function foo2 { echo $o->id; } } $d = new Objects; $d->foo; //will print 153 $d->foo2; //will print empty string happy codding http://www.php.net/manual/en/function.eval.php

« previous php.notes (#17776) next »