<?php
/**
 * 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);
    }
}

