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: 2010-08-07 15:38 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: Open Package: SPL related
PHP Version: 5.3.3RC3 OS: Irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC