note 86195 added to language.oop5.autoload

From: Date: Tue, 07 Oct 2008 17:23:41 +0000
Subject: note 86195 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-145133@lists.php.net to get a copy of this message
Because static classes have no constructor I use this to initialize such classes. The function init will (if available) be called when you first use the class. The class must not be included before, otherwise the init-function wont be called as autoloading is not used. <?php function __autoload($class_name) { require_once(CLASSES_PATH.$class_name.'.cls.php'); if(method_exists($class_name,'init')) call_user_func(array($class_name,'init')); return true; } ?> I use it for example to establish the mysql-connection on demand. It is also possilbe do add a destructor by adding this lines to the function: <?php if(method_exists($class_name,'destruct')) call_user_func(array($class_name,'destruct')); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 78.53.81.224 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- https://master.php.net/note/edit/86195 Del: integrated -- https://master.php.net/note/delete/86195/integrated Del: useless -- https://master.php.net/note/delete/86195/useless Del: bad code -- https://master.php.net/note/delete/86195/bad+code Del: spam -- https://master.php.net/note/delete/86195/spam Del: non-english -- https://master.php.net/note/delete/86195/non-english Del: in docs -- https://master.php.net/note/delete/86195/in+docs Del: other reasons-- https://master.php.net/note/delete/86195 Reject -- https://master.php.net/note/reject/86195 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145133) next »