Bug #75369 [Opn->Fbk]: spl_autoload_register prepend not working with nested require_once
| From: | requinix@php.net | Date: | Thu, 12 Oct 2017 23:40:29 +0000 |
| Subject: | Bug #75369 [Opn->Fbk]: spl_autoload_register prepend not working with nested require_once | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211665@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75369&edit=1
ID: 75369
Updated by: requinix@php.net
Reported by: tbollinger at ivesinc dot com
Summary: spl_autoload_register prepend not working with
nested require_once
-Status: Open
+Status: Feedback
Type: Bug
Package: SPL related
PHP Version: 7.1.10
Block user comment: N
Private report: N
New Comment:
What is the bug, exactly? Why do you expect that behavior? If bar() is prepended during execution of
foo() the autoload system isn't going to "go back" and use it, so when foo() ends
FooBar won't be present. As you said, if you append instead of prepend then it works.
Previous Comments:
------------------------------------------------------------------------
[2017-10-12 20:13:46] tbollinger at ivesinc dot com
Description:
------------
This bug requires three files to reproduce, since it is an issue with spl_autoload_register(),
specifically the prepend argument, and require_once().
Removing the prepend argument displays the expected result.
This was created using a base install of PHP 7.1.10.
Test script:
---------------
---- file1.php ----
<?php
function load() {
spl_autoload_register('foo');
}
function foo($class) {
echo __FUNCTION__ . "\n";
require_once('./file2.php');
}
load();
new FooBar();
---- file2.php ----
<?php
function bar($class) {
echo __FUNCTION__ . "\n";
require_once('./file3.php');
}
spl_autoload_register('bar', true, true);
---- file3.php ----
<?php
class FooBar {
public function __construct() { echo __CLASS__ . "\n"; }
}
Expected result:
----------------
foo
bar
FooBar
Actual result:
--------------
foo
foo
PHP Fatal error: Uncaught Error: Class 'FooBar' not found in
/home/user/phptest/file1.php:5
Stack trace:
#0 {main}
thrown in /home/user/phptest/file1.php on line 5
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75369&edit=1