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
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.