note 102202 added to function.spl-autoload-call
| From: | k dot varmark at gmail dot com | Date: | Wed, 02 Feb 2011 11:40:24 +0000 |
| Subject: | note 102202 added to function.spl-autoload-call | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176591@lists.php.net to get a copy of this message | ||
It should be noted, that calling spl_autoload_call on a child class, and then on its parent class,
throws a fatal error.
This happens because autoloading the child class also loads the class it extends. And since
spl_autoload_call forcibly calls the registered autoload function(s), not taking into account
whether the class exists, a fatal error is thrown:
File: child.class.php
<?php
class Child extends Parent () {
public function __construct () {
parent::__construct();
}
}
?>
File: parent.class.php
<?php
class Parent () {
public function __construct () {
}
}
?>
File: autoload.php
<?php
/* works fine */
spl_autoload_call('Child');
/* throws: Fatal error: Cannot redeclare class Parent in /parent.class.php on line 2 */
spl_autoload_call('Parent');
?>
----
Server IP: 195.184.96.15
Probable Submitter: 194.255.21.200
----
Manual Page -- http://www.php.net/manual/en/function.spl-autoload-call.php
Edit -- https://master.php.net/note/edit/102202
Del: integrated -- https://master.php.net/note/delete/102202/integrated
Del: useless -- https://master.php.net/note/delete/102202/useless
Del: bad code -- https://master.php.net/note/delete/102202/bad+code
Del: spam -- https://master.php.net/note/delete/102202/spam
Del: non-english -- https://master.php.net/note/delete/102202/non-english
Del: in docs -- https://master.php.net/note/delete/102202/in+docs
Del: other reasons-- https://master.php.net/note/delete/102202
Reject -- https://master.php.net/note/reject/102202
Search -- https://master.php.net/manage/user-notes.php