# RFC: Interest in function autoloading?

- Thread: https://staging.externals.io/message/109082
- Original archive: https://news-web.php.net/php.internals/109082
- Started by terje.slettebo@sandefjordbredband.net on 2020-03-17T00:32:27+00:00
- Messages: 2
- RFC: Function Autoloading (Withdrawn) — https://staging.externals.io/rfc/function_autoloading.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #109082 — terje.slettebo@sandefjordbredband.net — 2020-03-17T00:32:27+00:00

URL: https://staging.externals.io/message/109082#109082

Hi guys.

I've searched the archive, but I haven't found anything about this issue. 
I notice there exists an RFC for autoloading of functions, or more to the 
point, a unified autoloading system for classes, functions, constants and 
streams:

https://wiki.php.net/rfc/function_autoloading

Our systems use autoloading to great effect, letting us eliminate any require_once() 
to load classes. However, we also have a number of free functions, which 
unfortunately can't be loaded the same way and have to be explicitly loaded.

These included for example functions for array operations, and various functions 
used in our query builder. For example, we may write code like this:

$condition = ["date" => greater_than(<some date>)];

These functions have no place in a class, and having to prepend a class name 
just to make them auto-load leads to cluttered code, and feels forced. If 
you want to group such things, namespaces fits the bill.

Reading the RFC, it doesn't appear to have happened anything since 2015, 
so I'm wondering if this topic has been discussed at any time, and if so, 
what the outcome was?

In any case, I'd also be interested to hear people's opinion on this today.

I think this would be a great addition to eliminate clutter, and legitimate 
the use of free functions, which PHP honourably provides.

Regards,

Terje

---

## #109094 — tyson andre — 2020-03-17T03:20:35+00:00

URL: https://staging.externals.io/message/109082#109094 · In reply to: #109082

> I've searched the archive, but I haven't found anything about this issue. 
> I notice there exists an RFC for autoloading of functions, or more to the 
> point, a unified autoloading system for classes, functions, constants and 
> streams:

Hi Terje,

I'd brought this up 2 months ago in https://externals.io/message/107967 "Autoloading functions/consts without a performance impact"

One major issue is that foo() can refer to both foo() and NS\foo() from namespace NS,
and there's many different opinions on how/if an autoloader should deal with that, each with their own drawbacks.

If the ambiguity was avoided, then I think more people would be open to autoloading for functions/constants.
I had proposed one option for avoiding ambiguity for functions and constants, which was rejected: https://wiki.php.net/rfc/use_global_elements
I don't think the proposed alternatives would reach a 2/3 majority either if voted on, though, but may be mistaken.

- Tyson
