Re: [PHP-DEV] Draft RFC callable types + callable type/functionautoloading

This is only part of a thread. view whole thread
  110226
May 21, 2020 01:28 tysonandre775@hotmail.com (tyson andre)
Hi Dan Ackroyd,


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
  110227
May 21, 2020 01:54 tysonandre775@hotmail.com (tyson andre)
Hi Dan Ackroyd,

> 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.
I forgot, but I'd also started the thread https://externals.io/message/107967  ("Autoloading functions/consts without a performance impact") 5 months ago, and got sidetracked looking into ways to reduce ambiguity in calls to functions. It might have been a better idea for me to start a straw poll instead of that, but I didn't know how representative initial feedback was, and I'm no longer working on autoloading. Some of the messages might be relevant for the "Discussions" section of an RFC. Thanks, - Tyson