php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72459 please implement function autoloading
Submitted: 2016-06-20 11:44 UTC Modified: 2016-06-21 08:23 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: berserkaa73 at hotmail dot com Assigned:
Status: Suspended Package: *General Issues
PHP Version: 7.1.0alpha1 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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: berserkaa73 at hotmail dot com
New email:
PHP Version: OS:

 

 [2016-06-20 11:44 UTC] berserkaa73 at hotmail dot com
Description:
------------
I know there are plenty of bug reports about this, but I want to be sure this gets the renewed attention it deserves.

I've read some very stupid arguments against function autoloading, namely "just use OOP" "just use static methods" which are actual solutions, but hacks compared to what functional programming should look like. Or worse "you usually have one class per file, nobody wants one function per file" which is also stupid since one could do:

function autoloadFunction($namespacedFunctionName){
    $pos = strrpos($namespacedFunctionName, '\\');
    $nsName = substr($namespacedFunctionName, 0, $pos); // strips the function name
    $file = $nsName . DIRECTORY_SEPARATOR . 'functions.php'; // contains all the functions in the NS
    require($file);
}

... and would work perfectly fine. Not to mention that with opcache nobody worries of loading files performance as they are cached.

Can we have this, please? I was expecting this to be possible in 7.0 but apparently it's not going to happen even in 7.1: why?

Thank you





Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-20 14:09 UTC] cmb@php.net
> I know there are plenty of bug reports about this, […]

I quick search didn't show up any related tickets. Please point
out the other reports, so all but one can be marked as duplicates.

> Can we have this, please? I was expecting this to be possible in
> 7.0 but apparently it's not going to happen even in 7.1: why?

There has been a respective RFC[1] around for quite a while, but
it hasn't been pursued. I'm not sure why. Maybe you'll grab that
up? In that case you should contact Anthony (the author) first,
whether he's fine with it.

[1] <https://wiki.php.net/rfc/function_autoloading>
 [2016-06-21 08:23 UTC] krakjoe@php.net
-Status: Open +Status: Suspended
 [2016-06-21 08:23 UTC] krakjoe@php.net
There is already an RFC for this feature. 

An RFC is the proper way to push such a feature through.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 10:01:29 2024 UTC