|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-02-09 08:22 UTC] akademic at hub dot sknt dot ru
Description:
------------
In example below I expect that autoload call back will try to load class_two.
But it try to load existing class_one.
If you comment out 'extends class_two', autoload callback will not start.
Test script:
---------------
spl_autoload_register(function($class) {
var_dump('autoload '.$class);
});
test();
function test() {
$m = new class_one();
}
class class_one extends class_two {
function __construct() {
var_dump('I am '.__CLASS__);
}
}
Expected result:
----------------
string(18) "autoload class_two"
Actual result:
--------------
string(18) "autoload class_one"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 00:00:01 2025 UTC |
I've understood your first comment completly. And now I know what happens under the rug. And I've fixed my code now. I appreciate your help. Your example (`echo $x; $x = 1;`) is about _execution_. My example (`class class_one extends class_two`) is about _declaration_. I believe there is the difference. I understand technical reasons. But take a look on this case from PHP-user point. I have a class: `class class_one {}` And it works perfectly. Now I change it to `class class_one extends class_two {}` My thoughts: I don't have class_two in this file, but I have autoload function, which knows where class_two is located. So that's ok. Reality: Fatal error: Class 'class_one' not found. WTF? I haven't changed the names. I haven't moved code blocks around. I've simply added a little bit of inheritance and things have gone wrong. It shouldn't be that. Both situations (with and without inheritance) should fail or both situations should success.