Hi Dan Ackroyd, > Function + callable type autoloading > https://github.com/Danack/FunctionTypes/blob/master/2_autoloading_part_2.md
I'd be happy to see function autoloading support in php overall. It'd help in avoiding loading unnecessary polyfills, or in large codebases with many global functions that are only occasionally used. Autoloading functions involves a lot of tradeoffs due to design choices in PHP. I've seen a lot of different opinions - It might be worth setting up a straw poll for whether people would be interested in the change, unless you expect the php 8 implementation to be easy. (though straw polls have much lower response rates than RFCs) - Functions can be added to a namespace after they get added to the global scope. - A lot of namespaced php code refers to functions ambiguously (`namespace Foo; echo strlen($x);` can either refer to `strlen()` or `Foo\strlen`). What were your plans for handling ambiguous calls? I was in favor of checking if either existed (current behavior) before autoloading `Foo\strlen`, then before autoloading `strlen`, to keep performance acceptable. Others preferred various alternate approaches to autoloading. I don't think there was ever a straw poll to measure how common other opinions were, or if people would accept a given approach despite having a preference for something else. The alternatives I can imagine/remember from previous RFC discussions, *none of which I hold* (https://wiki.php.net/rfc/use_global_elements#deprecate_the_fallback_to_the_root_namespace_instead and below had somewhat related discussion as an attempt to reduce ambiguity): - The exact way to deal with ambiguity when autoloading, e.g. "autoload Foo\strlen() every single time strlen() is called" (I object because that would harm performance significantly) - You should make calling static methods easier (doesn't help with a lot of internal functionality like strlen() or polyfills for PECL functions are global functions) Other thoughts: - Maybe it would be useful/practical to initially *just* support autoloading functions when they're passed to function_exists($name, autoload: true) or autoload_function($name). I don't remember if that approach was suggested before. Then again, I'd personally want something more powerful than that due to the inconvenience, and I imagine most people would. Thanks, - Tyson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php