note 48635 deleted from language.variables.variable by tularis

From: Date: Sun, 02 Jan 2005 20:44:41 +0000
Subject: note 48635 deleted from language.variables.variable by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82620@lists.php.net to get a copy of this message
Note Submitter: o9i at free dot fr ---- A usefull usage of dynamic variable variable is the instanciation of all class in a directory. Try this for instance: /** * include all files of a directory './view' * * by pascal darmon * @copyright 2005 **/ $VIEW_DIRECTORY="./view"; $flink=opendir($VIEW_DIRECTORY); rewinddir($flink); while(($file=readdir($flink))!=""){ if ($file!="." & $file!="..") { require_once($VIEW_DIRECTORY . DIRECTORY_SEPARATOR . $file); } } // while // then instanciate all required class. rewinddir($flink); while(($file=readdir($flink))!=""){ if ($file!="." & $file!="..") { $classname=split("\.",$file); $classlist[]=$classname[0]; } } // while foreach($classlist as $classname){ eval("\$class_instance=new $classname;"); print "classe name : " . get_class($class_instance) . "<BR>"; $class_instance->display(); }

« previous php.notes (#82620) next »