note 24296 added to language.variables.variable

From: Date: Mon, 12 Aug 2002 17:05:48 +0000
Subject: note 24296 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-34878@lists.php.net to get a copy of this message
Another use for this feature in PHP is dynamic parsing.. Due to the rather odd structure of an input string I am currently parsing, I must have a reference for each particular object instantiation in the order which they were created. In addition, because of the syntax of the input string, elements of the previous object creation are required for the current one. Normally, you won't need something this convolute. In this example, I needed to load an array with dynamically named objects - (yes, this has some basic Object Oriented programming, please bare with me..) <?php include("obj.class"); // this is only a skeletal example, of course. $object_array = array(); // assume the $input array has tokens for parsing. foreach ($input_array as $key=>$value){ // test to ensure the $value is what we need. $obj = "obj".$key; $$obj = new Obj($value, $other_var); Array_Push($object_array, $$obj); // etc.. } ?> Now, we can use basic array manipulation to get these objects out in the particular order we need, and the objects no longer are dependant on the previous ones. I haven't fully tested the implimentation of the objects. The scope of a variable-variable's object attributes (get all that?) is a little tough to crack. Regardless, this is another example of the manner in which the var-vars can be used with precision where tedious, extra hard-coding is the only alternative. -- http://www.php.net/manual/en/language.variables.variable.php http://master.php.net/manage/user-notes.php?action=edit+24296 http://master.php.net/manage/user-notes.php?action=delete+24296 http://master.php.net/manage/user-notes.php?action=reject+24296

« previous php.notes (#34878) next »