Re: Function/Constant autoloading
| From: | Sebastian Krebs | Date: | Tue, 26 Jul 2011 08:39:59 +0000 |
| Subject: | Re: Function/Constant autoloading | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-54199@lists.php.net to get a copy of this message | ||
Hi,
thanks for your reply, but I'm not talking about class loading (because thats already possible). I'm talking about autoloading of userspace functions and constants
// /path/to/my/functions.php
namespace my\functions;
const THING = 'I am constant!';
function helloWorld () {
echo "hello World;} // /path/to/some/other/file.php namespace foo; use my\functions; functions\helloWorld(); // fail! echo functions\THING; Am 26.07.2011 10:27, schrieb Laruence:
Hi:maybe Yaf_Loader can be used for meet this requirement.it's a internal autoload function:Each namespace separator is converted to a DIRECTORY_SEPARATOR whenloading from the file system.Each "_" character in the CLASS NAME is converted to aDIRECTORY_SEPARATOR. The "_" character has no special meaning in the namespace. The fully-qualified namespace and class is suffixed with ".php" when loading from the file system.As examples: \Doctrine\Common\IsolatedClassLoader =>/path/to/project/lib/vendor/Doctrine/Common/IsolatedClassLoader.php\namespace\package\Class_Name =>/path/to/project/lib/vendor/namespace/package/Class/Name.php\namespace\package_name\Class_Name =>/path/to/project/lib/vendor/namespace/package_name/Class/Name.phphttp://pecl.php.net/package/Yafthanks 2011/7/26 Sebastian Krebs<sebastian.krebs.berlin@googlemail.com>:Hi, Maybe this topic occured already, then sorry when I'm wasting your time, but I'm wondering, why there is no autoloading for functions and (namespace)constants. When a class is not found, then an userland function is called. Thus I don't see a reason, why something like this doesn't exists for functions and (namespace)constants too, because using them is quite uncomfortable right now compared to classes and the decision _how_ to load them would be on the developers-side anyway. Sebastian Krebs -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php