Hi All,

In the discussion of escaping mechanisms, it's once again come up that functions lack autoloading, and thus are hard to work with in larger code bases.

Previous solutions to this, most notably Anthony Ferrara's very thorough RFC [1], have looked at adding new modes for the existing autoload functions, or new functions alongside, to specify the type being autoloaded.

A common response is that you can just use a class with static methods, and thus leverage the existing autoload mechanism. But the introduction of "static class" or "abstract final class" was rejected [2] in part with the opposite justification: that you shouldn't need a class to hold static methods now that we have namespaced functions.

How about an alternative approach where a function inside a namespace can be autoloaded using the existing callback, by using a reserved namespace segment? So to autoload function "foo\bar()", the engine would construct a string like "__function\foo\bar" or "foo\__function\bar", and pass that to the registered autoloader stack.

This shouldn't result in errors or misbehaviour from existing autoloaders, it just won't find anything to load. An autoloader that knows how can then use the namespace path to determine what to load, probably something like "src/foo/functions.php".

The focus on namespaced functions reflects the fact that one-file-per-function is rare and somewhat unwieldy, so a call to load "__function\foo" is unlikely to be that useful in practice.

Note that, like many previous proposals, this could apply to namespaced constants, too, using a token such as __constant.

Any thoughts? Good idea, horrible idea?

[1] https://wiki.php.net/rfc/function_autoloading
[2] https://wiki.php.net/rfc/abstract_final_class

Regards,


--
Rowan Collins
[IMSoP]


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

Reply via email to