note 102180 added to function.spl-autoload-register
| From: | lv) | Date: | Tue, 01 Feb 2011 09:57:34 +0000 |
| Subject: | note 102180 added to function.spl-autoload-register | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176552@lists.php.net to get a copy of this message | ||
When using spl_autoload_register() with class methods, it might seem that it can use only public
methods, though it can use private/protected methods as well, if registered from inside the class:
<?php
class ClassAutoloader {
public function __construct() {
spl_autoload_register(array($this, 'loader'));
}
private function loader($className) {
echo 'Trying to load ', $className, ' via ', __METHOD__,
"()\n";
include $className . '.php';
}
}
$autoloader = new ClassAutoloader();
$obj = new Class1();
$obj = new Class2();
?>
Output:
--------
Trying to load Class1 via ClassAutoloader::loader()
Class1::__construct()
Trying to load Class2 via ClassAutoloader::loader()
Class2::__construct()
----
Server IP: 212.93.96.97
Probable Submitter: 62.85.2.100
----
Manual Page -- http://www.php.net/manual/en/function.spl-autoload-register.php
Edit -- https://master.php.net/note/edit/102180
Del: integrated -- https://master.php.net/note/delete/102180/integrated
Del: useless -- https://master.php.net/note/delete/102180/useless
Del: bad code -- https://master.php.net/note/delete/102180/bad+code
Del: spam -- https://master.php.net/note/delete/102180/spam
Del: non-english -- https://master.php.net/note/delete/102180/non-english
Del: in docs -- https://master.php.net/note/delete/102180/in+docs
Del: other reasons-- https://master.php.net/note/delete/102180
Reject -- https://master.php.net/note/reject/102180
Search -- https://master.php.net/manage/user-notes.php