note 89173 deleted from language.oop5.autoload by peehaa

From: Date: Mon, 08 Jul 2013 20:48:28 +0000
Subject: note 89173 deleted from language.oop5.autoload by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-195530@lists.php.net to get a copy of this message
Note Submitter: adam at greatbigmassive dot net ---- I've been playing with the idea of automatically running the __construct() function after initiating a static/singleton class. As we know, it doesn't run unless you create new instance() of the class which doesn't happen on the singleton method. I've seen the methods of using the "getInstance" call but this is a manual call that I wanted to avoid. As an additional idea I've done this and would be interested in opinions. Seems to work for me and my framework and it means I don't have to run the __construct() manually via the internal "new self" method. Obviously, in this case, I probably don't even need to call the booter function __construct() but for relationship recognition I have. Basic idea ---------- Make the __construct() protected instead of private. This means an extended class can access/override it. Then, in autoload, I use eval to extend the class I've just initiated which simply runs the parent __construct() if it exists.. <?php function __autoload($class){ require_once(INC_FILES."/class/class.".$class.".php"); if(method_exists($class,'__construct')){ eval("class al_$class extends $class{function __construct(){parent::__construct();}}new al_$class;"); } return true; } ?>

« previous php.notes (#195530) next »