note 48635 added to language.variables.variable
| From: | o9i at free dot fr | Date: | Sun, 02 Jan 2005 20:34:01 +0000 |
| Subject: | note 48635 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82617@lists.php.net to get a copy of this message | ||
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();
}
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48635
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48635&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48635&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48635&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48635&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48635&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48635&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48635&report=yes
Search -- http://master.php.net/manage/user-notes.php