Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Mike Schinkel
> On Jan 3, 2020, at 9:48 AM, Rowan Tommins wrote: > > However, if we're looking at radical changes of direction, I wonder if we > should instead plan to phase out autoloading itself. Yes. Please. Autoloading is a medicine that is almost worse than the disease. -Mike -- PHP Internals - PH

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Mike Schinkel
> On Jan 3, 2020, at 6:22 AM, Rasmus Schultz wrote: > > I will just briefly mention an alternative idea I've brought up before. > (there's no RFC for this.) > >use function MyClass::myStaticFunction; > >myStaticFunction(); This strikes me as an excellent approach. Well-spent five cent

Re: [PHP-DEV] Initializing constants once, with code?

2020-01-03 Thread Larry Garfield
On Fri, Jan 3, 2020, at 12:55 PM, Mike Schinkel wrote: > Hi Larry, > > Thanks for replying. > > > It seems to me it would be much cleaner to just... build that into a > > static method call with the derivation-and-caching logic behind the scenes. > > It's not complicated code. > > That is ex

Re: [PHP-DEV] Initializing constants once, with code?

2020-01-03 Thread Vesko Kenashkov
On Fri, Jan 3, 2020 at 8:55 PM Mike Schinkel wrote: > ... > > OTOH, if PHP 8.x would allow functions w/o parameters to be called w/o > parenthesis then your approach satisfy the use-case: > > class Stuff { > protected $val; > > public static function VAL() { > self::$val ??= comp

Re: [PHP-DEV] Initializing constants once, with code?

2020-01-03 Thread Mike Schinkel
Hi Larry, Thanks for replying. > It seems to me it would be much cleaner to just... build that into a static > method call with the derivation-and-caching logic behind the scenes. It's > not complicated code. That is exactly what I have been doing, and what I am finding suboptimal. The prob

Re: [PHP-DEV] Initializing constants once, with code?

2020-01-03 Thread Larry Garfield
On Thu, Jan 2, 2020, at 6:39 PM, Mike Schinkel wrote: > > On Jan 2, 2020, at 7:09 PM, tyson andre wrote: > > > >> The problem with using constants is that the value is still hardcoded > >> and if we later want to change to pulling the data from a config file > >> we have to change all the code t

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Rowan Tommins
On Fri, 3 Jan 2020 at 15:21, tyson andre wrote: > > 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

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread tyson andre
> If the call to foo() is simply treated equivalently to a call to A::foo(), > then this may have some quite surprising behavior: > > If A::foo() is an instance method, then this call to foo() will inherit > $this, > which is something that normally does not happen with free-standing function >

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread tyson andre
> 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

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Rowan Tommins
On Fri, 3 Jan 2020 at 14:39, tyson andre wrote: > > namespace Foo; > > echo strlen('hello'); // Finds a global function at step 2, so doesn't > > trigger the autoloader > > echo \Foo\strlen('hello'); // Explicitly namespaced function, so triggers > > the autoloader > > echo strlen('hello'); // Sh

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Rowan Tommins
On Fri, 3 Jan 2020 at 11:37, Nikita Popov wrote: > Overall though, I do tend to agree that the use of static methods is at > this point more idiomatic than the use of free-standing functions, and it > might make more sense to go in that direction. > Perhaps a way forward would be to effectively

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread tyson andre
> If we cache the resolution to global function at line 2, removing that line > changes the rest of the program. If we don't cache it there, then what > happens if we run this code in a loop? It (and my proposed autoloader change) changes it for that call (at that opcode, i.e. for the call at that

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Rowan Tommins
On Fri, 3 Jan 2020 at 01:51, tyson andre wrote: > 1. It (first) looks for a function from the current namespace: A\B\foo(). > 2. It (next) tries to find and call the global function foo(). > 3. (Optional) NEW ADDITION: Next, if both functions were undefined, >the autoloader(s) attempt to auto

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Nikita Popov
On Fri, Jan 3, 2020 at 12:22 PM Rasmus Schultz wrote: > On Fri, Jan 3, 2020 at 10:35 AM Nikita Popov wrote: > >> On Fri, Jan 3, 2020 at 2:51 AM tyson andre >> wrote: >> >> > After a quick search, it turns out I've mostly reinvented >> > https://wiki.php.net/rfc/autofunc which I hadn't remembere

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Rasmus Schultz
On Fri, Jan 3, 2020 at 10:35 AM Nikita Popov wrote: > On Fri, Jan 3, 2020 at 2:51 AM tyson andre > wrote: > > > After a quick search, it turns out I've mostly reinvented > > https://wiki.php.net/rfc/autofunc which I hadn't remembered. > > The `spl_autoload_*()` changes it mentions is what I had

Re: [PHP-DEV] Autoloading functions/consts without a performance impact

2020-01-03 Thread Nikita Popov
On Fri, Jan 3, 2020 at 2:51 AM tyson andre wrote: > After a quick search, it turns out I've mostly reinvented > https://wiki.php.net/rfc/autofunc which I hadn't remembered. > The `spl_autoload_*()` changes it mentions is what I had in mind > > There's been changes to php since then, it's been 7 y