note 75037 deleted from language.oop5.magic by cmb
| From: | cmb@php.net | Date: | Sun, 10 Nov 2019 12:39:26 +0000 |
| Subject: | note 75037 deleted from language.oop5.magic by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212988@lists.php.net to get a copy of this message | ||
Note Submitter: alejandro dot gama at gmail dot com
----
Referering my previus note: there was an error in the code. But i find a better way:
<?
session_start();
class Classes{
private $name;
private $statics;
function __construct($name){
$this->name=$name;
$this->statics=array();
}
function setStatic($k,$v){
if(!is_resource($v))
$this->statics[$k]=$v;
}
function __wakeup(){
foreach($this->statics as $k=>$v)
eval($this->name."::\$".$k."=\$this->statics['".$k."'];");
}
}
function storeStaticAttributes(){
$classes=get_declared_classes();
foreach($classes as $name){
$reflect=new ReflectionClass($name);
if($reflect->isUserDefined()){
$statics=$reflect->getStaticProperties();
if(empty($_SESSION["_classes"]))
$_SESSION["_classes"]=array();
if(empty($_SESSION["_classes"][$name]))
$_SESSION["_classes"][$name]=new Classes($name);
foreach($statics as $k=>$v)
$_SESSION["_classes"][$name]->setStatic($k,$v);
}
}
}
register_shutdown_function('storeStaticAttributes');
?>