<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

Of course, PHP ain't Python, and functions aren't first class language properties; despite PHPs actual more scripty features and pioneering in that regard.

While technical assessing did crop up, recent discussions actually circled around preferences. Cargo culters aren't pleased with consolidating language semantics for *second-rate* coding paradigms. The groupthink being "Only class-wrapped code is quality code". (Casual alluding to here in the parens for no reason whatsoever.)


### Why is it in shared.phar ?

It's a proof-of-concept mostly.

Implementing function declaration lookups is a *trivial* by-product of doing things properly anyway.


### How can I use it *now*?

For current PHP versions, you need a workaround like this to shoehorn globally-autoloaded functions into your code:

        /**
         * Userland workaround for function_autoloading.
         * Implements a static class, which random global functions can be
         * invoked with.
         *
         *    x::autoload_me(1,2,3);
         *
         */

        class x {
            function __callStatic($name, $args=array()) {
                if (!function_exists($name)) {

                    static $ca;

                    find suitable autoloaders
                    if (!isset($ca)) {
                        $ca = array();

                        foreach (array_filter("is_object", spl_autoload_functions()) as $spl) {
                            if (is_a($spl, "Canonic_Autoloader")) {
                                $ca[] = $spl;
                            }
                        }
                    }

                    invoke each autoloader
                    foreach ($ca as $autoload) {
                        $autoload($name, 2);
                    }
                }

                return call_user_func_array($name, $args);
            }
        }

Which obviously is hardly as enchanting as having PHP adhere to its hybrid heritage. And `x::` while an acceptably readable prefix, is not a standard denomination for such a feature.

Though the bemusing part here is, you just need to place `x.php` in your classpath. Then `shared.phar` will autoload both subsequently; first the static `x::` class, then your `autoloaded_func()` prior calling it.