Re: Not autoloading functions

From: Date: Fri, 27 Jan 2017 09:23:38 +0000
Subject: Re: Not autoloading functions
Groups: php.internals 
Request: Send a blank email to internals+get-97983@lists.php.net to get a copy of this message
An alternative (which I haven't properly developed yet). Thoughts? ``` define_autoload(AUTOLOAD_NS, function($ns){ if($ns === '\A\B\C'){ echo "LOADING ABC\n"; require(__DIR__ . $ns . '\functions_and_constants.php'); } }); define_autoload(AUTOLOAD_NS, function($ns){ if($ns === '\A\B'){ echo "LOADING AB\n"; require(__DIR__ . $ns . '\functions_and_constants.php'); } }); define_autoload(AUTOLOAD_NS, function($ns){ if($ns === '\B'){ echo "LOADING A\n"; require(__DIR__ . $ns . '\functions_and_constants.php'); } }); \A\B\someFunction(); // prints: // LOADING A\n // LOADING AB\n \A\B\someFunction(); // tries no autoload, because both namespaces A and A\B were // attempted to be loaded already. // in other words, autoload is attempted only once // for any given namespace \A\B\C\someOtherFunction(); // prints: // LOADING ABC\n // because contrarily to super namespaces, A\B\C wasn't // attempted to be loaded yet ```

« previous php.internals (#97983) next »