php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52385 Support for autoloading functions
Submitted: 2010-07-21 05:29 UTC Modified: 2018-06-17 12:27 UTC
Votes:8
Avg. Score:4.5 ± 1.3
Reproduced:6 of 7 (85.7%)
Same Version:4 (66.7%)
Same OS:5 (83.3%)
From: php-bugs at majkl578 dot cz Assigned:
Status: Suspended Package: SPL related
PHP Version: 5.3.3RC3 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php-bugs at majkl578 dot cz
New email:
PHP Version: OS:

 

 [2010-07-21 05:29 UTC] php-bugs at majkl578 dot cz
Description:
------------
Would it be possible to add a support for autoloading user-defined functions? Currently only classes are supported by either __autoload or spl_autoload or spl_autoload_register.

Including all functions is really awful job whereas classess could be autoloaded nicely (imagine implementation for spl_autoload_register which scans a directory for classess and then includes specific file).

I suggest to make possible something similar to the example above for normal functions (global as well as those in namespaces).

PS: I know that it could be hacked by emulating namespace with class (eg. static method String::webalize()) but since PHP 5.3 it would be probably nicier not to hack it with classes, but place it to namespace as a regular function (String\webalize()).


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-24 07:00 UTC] php-bugs at majkl578 dot cz
Decoded version (really nice bug :)):

Would it be possible to add a support for autoloading user-defined functions? Currently only classes are supported by either __autoload or spl_autoload or spl_autoload_register.

Including all functions is really awful job whereas classess could be autoloaded nicely (imagine implementation for spl_autoload_register which scans a directory for classess and then includes specific file).

I suggest to make possible something similar to the example above for normal functions (global as well as those in namespaces).

PS: I know that it could be hacked by emulating namespace with class (eg. static method String::webalize()) but since PHP 5.3 it would be probably nicier not to hack it with classes, but place it to namespace as a regular function (String\webalize()).
 [2010-08-07 01:51 UTC] johannes@php.net
With classes you often have one class per file, with functions not which makes the lookup usually way more complex; I don't see us adding this.
 [2010-08-07 15:38 UTC] php-bugs at majkl578 dot cz
It doesn't make any difference to me. I'm using tokenizer to look up for classes in all files. Then I store them in an associative array (class=>file) and when the class is requested, it is loaded according to this list.
With functions it'd be completely same. I don't think PHP should provide anything more, just an autoloader to be used with user-defined callback (like spl_autoload_register does).

"With classes you often have one class per file…"
Often, but not always.
 [2018-06-17 12:27 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2018-06-17 12:27 UTC] cmb@php.net
This feature clearly requires the RFC process.  Either the
existing RFC “Function Autoloading”[1] may be revived, or a new
RFC should be submitted[2].  I'm suspending this ticket for the
time being.

[1] <https://wiki.php.net/rfc/function_autoloading>
[2] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Tue Oct 23 04:01:25 2018 UTC