Hi,

Thanks, that looks similar to what I'm looking for. It doesn't seem, that any of the reply is really against autoloading of functions (and maybe constants), but are against the given implementations (because they are built on top of the outdated __autoload() function), what brings me back to my "overall" question: Why it doesn't exists, but autoloading of classes exists? That makes me feel, that, since classes exists, functions (and the youngest children namespace constants) are the unloved children of the multiparadigma approach.



Just to make an example, what goes on in my mind:


// register-autoload signature
spl_autoload_register($callback, $type = SPL_AUTOLOAD_CLASS);

// register an autoloader
spl_autoload_register(function ($name, $type) use ($myLoader) {
    switch ($type) {
        case SPL_AUTOLOAD_CLASS:
            return $myLoader->loadClass($name);
            break;
        case SPL_AUTOLOAD_FUNCTION:
            return $myLoader->loadFunction($name);
            break;
        case SPL_AUTOLOAD_CONSTANT:
            return $myLoader->loadConstant($name);
            break;
    }
}, SPL_AUTOLOAD_CLASS | SPL_AUTOLOAD_FUNCTION | SPL_AUTOLOAD_CONSTANT);


class-only-autoloader can simply ignore the second argument `$type`, thus I don't see any BC-break.


Am 26.07.2011 10:53, schrieb Ferenc Kovacs:
On Tue, Jul 26, 2011 at 10:39 AM, Sebastian Krebs
<sebastian.krebs.ber...@googlemail.com>  wrote:
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;



I think it's pretty clear what are you after.
autofunc with a patch:
http://www.mail-archive.com/internals@lists.php.net/msg43983.html

__autodefine proposal and rfc:
http://www.mail-archive.com/internals@lists.php.net/msg48986.html
https://wiki.php.net/rfc/autodefine?s[]=autodefine

from  the replies I think that the idea didn't got traction from the core devs.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to