Wiki page
[rfc:function_autoloading] by
mario
2014-09-04 22:53:48.
D 2014-09-04T22:53:48.389
L rfc:function_autoloading
N text/x-markdown
P 1803896e226c2c985ce2bf23a778d6cb95df0d7f
U mario
W 1750
<h3> Function autoloading </h3>
PHP is a *hybrid* language. It however unevenly implements autoloading for classes only as of now. There are long-standing feature requests for supporting it with all language symbols. A more recent attempt to bring some systematization here was:
See [https://wiki.php.net/rfc/function_autoloading](https://wiki.php.net/rfc/function_autoloading)
The ensuing php-dev discussion wasn't overly constructive. (Fatal errors provide a higher performance than autoloading a function). Backhandedly however to prevent functions becoming first class language constructs, due to them implying an unfavored coding paradigm.
Meanwhile PHP 5.6 introduced [`use function`](https://wiki.php.net/rfc/use_function) imports - which however are aliases only, thus magnifying the dichotomy only further.
### Why is it in shared.phar ?
With `shared.phar` revisiting the big picture was a design goal, not repeating what's already there.
* Function autoloading here is a **proof-of-concept** mostly.
* Requires little additional effort for the autoloader.
* And implementing it in the map generator was a *trivial* by-product of doing things properly anyway.
It still can be be optionalized however, when unneeded.
### How can I use it *now*?
See the attached example, which shows the common `class::__callStatic()` workaround for current PHP versions. While such a class wrapper bemusingly gets autoloaded itself, it's probably only suitable for e.g. application-level plugin hook schemes.
The lack of core language support makes it unsuitable for autoloading *namespaced* functions. It can just shoehorn in global functions easily, or else required `x::{"pkg\\bundle\\func"}()` invocations.
Z 4282730da0475846e09bce7e2281c772