Bug #75369 [Opn->Csd]: spl_autoload_register prepend not working with nested require_once

From: Date: Fri, 13 Oct 2017 17:46:42 +0000
Subject: Bug #75369 [Opn->Csd]: spl_autoload_register prepend not working with nested require_once
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211676@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 User updated by: tbollinger at ivesinc dot com Reported by: tbollinger at ivesinc dot com Summary: spl_autoload_register prepend not working with nested require_once -Status: Open +Status: Closed Type: Bug Package: SPL related PHP Version: 7.1.10 Block user comment: N Private report: N New Comment: Closing ticket. Previous Comments: ------------------------------------------------------------------------ [2017-10-13 17:45:41] tbollinger at ivesinc dot com Thank you, your comment makes sense. I mistakenly thought that the prepended bar() would be interpreted and the require_once() would be executed. This can be closed as "not a bug". Thanks again for your time! ------------------------------------------------------------------------ [2017-10-12 23:40:28] requinix@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#211676) next »