php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71236 Second call of spl_autoload_register() does nothing if it has no arguments
Submitted: 2015-12-29 12:39 UTC Modified: 2020-06-10 07:43 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:-2 (-100.0%)
From: php at maisqi dot com Assigned: nikic (profile)
Status: Closed Package: SPL related
PHP Version: Irrelevant OS: Windows and Linux
Private report: No CVE-ID: None
 [2015-12-29 12:39 UTC] php at maisqi dot com
Description:
------------
spl_autoload_register() with no arguments registers spl_autoload(). But if we call spl_autoload_register() with a custom function before, it does nothing.
Nothing in the documentation seems to support this behaviour as valid.

Tested on PHP 5.5 Linux, 5.6 Win64 and 7.01 Win64.

Test script:
---------------
<?php
echo '<pre>';
/**
 * Every one of these code blocks must be run in separated.
 */
// Custom function first; spl_autoload after.
spl_autoload_register(function ($class) {});
spl_autoload_register();
print_r(spl_autoload_functions());	// Prints only one entry.
/*

// Custom function first; spl_autoload after.
spl_autoload_register(function ($class) {});
spl_autoload_register('spl_autoload');
print_r(spl_autoload_functions());	// Prints two entries, as expected.

// spl_autoload first; custom function after.
spl_autoload_register();
spl_autoload_register(function ($class) {});
print_r(spl_autoload_functions());	// Prints two entries, as expected.
*/

Expected result:
----------------
All blocks should print two entries.

Actual result:
--------------
All blocks should print two entries, except the first that only prints one.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-29 12:41 UTC] php at maisqi dot com
In "Actual results" should be:

   The first block prints one entry; the others print two blocks.
 [2015-12-29 14:15 UTC] laruence@php.net
maybe a warning?
 [2015-12-29 19:59 UTC] php at maisqi dot com
Sorry, I don't understand what you mean.
Are you suggesting issuing a warning for this? Reading the docs, I get the idea that the order of the spl_autoload_register() calls is irrelevant -- it uses a queue, after all -- so, I don't see where a warning could fit.
 [2015-12-29 20:02 UTC] php at maisqi dot com
"The autoload function being registered. If no parameter is provided, then the default implementation of spl_autoload() will be registered."
 [2020-06-09 16:06 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2020-06-10 07:43 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC