Re: Autoloading functions/consts without a performance impact

From: Date: Fri, 03 Jan 2020 15:21:15 +0000
Subject: Re: Autoloading functions/consts without a performance impact
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-107976@lists.php.net to get a copy of this message
> Now the behaviour of my program can completely change depending on which of > those functions I call first, which might even depend on user input. > Regardless of exactly how the cache works, that kind of unpredictability is > a recipe for disaster. It already does completely change depending on user input, without autoloading, in the same way. I assume you're arguing against autoloading without autoloading \NS\strlen every time, but I still consider the approach I'm proposing an improvement over existing unpredictable behavior. > The only way to make it predictable again is to pre-define the namespaced > function in my startup code, at which point I don't need function > autoloading. Other use cases would benefit from function autoloading, though. The use case in your example is very different from the common use case I have in mind for proposing autoloading - name reuse should be uncommon in practice. Adding "use NS\strlen", "namespace\strlen", etc. are alternatives to make it predictable I'd consider reusing the name from the global namespace intentionally to be a code smell. Overlap might be unavoidable for common names such as \NS\run() in some libraries, but hopefully they'd preload the entire file of functions for those, or be in a different namespace from the code using those libraries, and other libraries (e.g. polyfills in global namespace) could still use autoloading.

« previous php.internals (#107976) next »