public static function initialize()
    {
        static $initialized = false;
        static $structures  = array();

        if (defined('T_CALLABLE')) {
            return;
        }

        if (!$initialized) {
            spl_autoload_register(
                function ($class) {
                    $parts  = array_map('strrev', explode('\\', strrev($class), 2));
                    $short  = array_shift($parts);
                    $ns     = (string) array_shift($parts);

                    if ($short === 'callable') {
                        // The class to load is "callable", inject the alias.
                        if (class_alias('\\Erebot\\CallableInterface', $class, true) !== true) {
                            throw new \RuntimeException('Could not load wrapper');
                        }
                        return true;
                    }

                    // Otherwise, inject the alias in the namespace
                    // of the class being loaded.
                    class_exists("$ns\\callable");
                    return false;
                },
                true
            );
            $initialized = true;
        }

        // Inject the alias in existing namespaces.
        $funcs  = get_defined_functions();
        $new    = array_merge(
            $funcs['user'],
            get_declared_classes(),
            get_declared_interfaces()
        );

        if ($new != $structures) {
            $newNS = array();
            foreach (array_diff($new, $structures) as $structure) {
                    $parts = explode('\\', strrev($structure), 2);
                    array_shift($parts); // Remove class/interface name.
                    $newNS[] = (string) array_shift($parts);
            }
            $structures = $new;
            $newNS      = array_unique($newNS);
            foreach ($newNS as $ns) {
                class_exists(strrev($ns) . '\\callable');
            }
        }
    }
public static function initialize()
    {
        static $initialized = false;
        static $structures  = array();

        if (defined('T_CALLABLE')) {
            return;
        }

        if (!$initialized) {
            spl_autoload_register(
                function ($class) {
                    $parts  = array_map('strrev', explode('\\', strrev($class), 2));
                    $short  = array_shift($parts);
                    $ns     = (string) array_shift($parts);

                    if ($short === 'callable') {
                        // The class to load is "callable", inject the alias.
                        if (class_alias('\\Erebot\\CallableInterface', $class, true) !== true) {
                            throw new \RuntimeException('Could not load wrapper');
                        }
                        return true;
                    }

                    // Otherwise, inject the alias in the namespace
                    // of the class being loaded.
                    class_exists("$ns\\callable");
                    return false;
                },
                true
            );
            $initialized = true;
        }

        // Inject the alias in existing namespaces.
        $funcs  = get_defined_functions();
        $new    = array_merge(
            $funcs['user'],
            get_declared_classes(),
            get_declared_interfaces()
        );

        if ($new != $structures) {
            $newNS = array();
            foreach (array_diff($new, $structures) as $structure) {
                    $parts = explode('\\', strrev($structure), 2);
                    array_shift($parts); // Remove class/interface name.
                    $newNS[] = (string) array_shift($parts);
            }
            $structures = $new;
            $newNS      = array_unique($newNS);
            foreach ($newNS as $ns) {
                class_exists(strrev($ns) . '\\callable');
            }
        }
    }
public static function initialize ( ) { static $ initialized = false ; static $ structures = array ( ) ; if ( defined ( 'T_CALLABLE' ) ) { return ; } if ( ! $ initialized ) { spl_autoload_register ( function ( $ class ) { $ parts = array_map ( 'strrev' , explode ( '\\' , strrev ( $ class ) , 2 ) ) ; $ short = array_shift ( $ parts ) ; $ ns = ( string ) array_shift ( $ parts ) ; if ( $ short === 'callable' ) { // The class to load is "callable", inject the alias. if ( class_alias ( '\\Erebot\\CallableInterface' , $ class , true ) !== true ) { throw new \ RuntimeException ( 'Could not load wrapper' ) ; } return true ; } // Otherwise, inject the alias in the namespace // of the class being loaded. class_exists ( "$ns\\callable" ) ; return false ; } , true ) ; $ initialized = true ; } // Inject the alias in existing namespaces. $ funcs = get_defined_functions ( ) ; $ new = array_merge ( $ funcs [ 'user' ] , get_declared_classes ( ) , get_declared_interfaces ( ) ) ; if ( $ new != $ structures ) { $ newNS = array ( ) ; foreach ( array_diff ( $ new , $ structures ) as $ structure ) { $ parts = explode ( '\\' , strrev ( $ structure ) , 2 ) ; array_shift ( $ parts ) ; // Remove class/interface name. $ newNS [ ] = ( string ) array_shift ( $ parts ) ; } $ structures = $ new ; $ newNS = array_unique ( $ newNS ) ; foreach ( $ newNS as $ ns ) { class_exists ( strrev ( $ ns ) . '\\callable' ) ; } } }
Initialize the wrapper.

\param bool $existing
(optional) Whether to inject the wrapper inside existing
namespaces. You don't need to pass this argument: the wrapper
already does so internally when needed.

\note
This method must be called before using any of the wrapper's
other methods. It registers an autoloader that automatically
adds a "callable" typehint to namespaces on PHP 5.3.x when
a new class/interface is autoloaded.

\note
This method needs to be called only once, unless you're using
functions or requiring/including files manually, in which case
it is advisable to call this method periodically (eg. using
register_tick_function() and declare(ticks=N) with an adequate
value for N depending on your code).
Initialize the wrapper .