php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51150 spl_autoload_extensions() should accept arrays to avoid invalid separators
Submitted: 2010-02-25 20:22 UTC Modified: 2020-11-18 14:12 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jo at feuersee dot de Assigned:
Status: Suspended Package: SPL related
PHP Version: 5.3.1 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jo at feuersee dot de
New email:
PHP Version: OS:

 

 [2010-02-25 20:22 UTC] jo at feuersee dot de
Description:
------------
spl_autoload_extensions() accepts a string with a , separated list of
filename parts to register for autoloading.
This results in filenames containing a , as an extension filename
become impossible to register.
It should be possible to pass an array to circumvent any restriction
cased by the string based argument.

I know that ppl might consider it strange to use , as part of a
filename.

IMHO there may be cases where it might be necessary. Considering that
arrays are a native PHP data type, it would be a better design.

Reproduce code:
---------------
spl_autoload_extensions(array('.class.php', '.php'));
myclass::hello();

Expected result:
----------------
Hello world

Actual result:
--------------
Warning: spl_autoload_extensions() expects parameter 1 to be string,
array given in [test.php] on line ## 
Fatal error: Class 'myclass' not found in [test.php] on line ## 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-01 20:05 UTC] pajoye@php.net
-Package: Feature/Change Request +Package: SPL related
 [2010-03-01 21:16 UTC] jani@php.net
-Operating System: Any +Operating System: *
 [2010-03-02 03:27 UTC] kalle@php.net
Using implode() would really be enough here, I'm not sure whether we should add that option or not, but it is indeed not a bad idea.

As a workaround you may want to do:
spl_autoload_extensions(implode(',', $extensions));
 [2010-03-02 09:21 UTC] jo at feuersee dot de
This is not about that I have a list of extensions in an array and that I am
unable to use implode to pass this to spl_autoload_extension() as a string.

This bug report is about that the design of spl_autoload_extension() would be
better if it accepts an array.
Using a whatether separated string implies that the whatether character can't be
a valid part of the argument list. An array does not have this limitation.
 [2020-11-18 14:12 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2020-11-18 14:12 UTC] cmb@php.net
At this point in time, it may be more appropriate to deprecate
spl_autoload_extension() and spl_autoload().  If you, or anybody
else, is still interested in this feature, please forward the
request to the internals mailing list for discussion.  For the
time being, I'm suspending this ticket.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 04:01:27 2025 UTC