Re: Anonymous functions inside static methods.

From: Date: Sun, 11 May 2014 04:38:22 +0000
Subject: Re: Anonymous functions inside static methods.
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
> Yes... but we fix bugs all the time that are technically BC breaks. Do you
> really think we shouldn't fix this?

My thought was: if there's a place for get_called_class() in a closure
in production code, it's been tested to expect the current behavior.
Every time I've used g_c_c() it was to set up some delicate runtime
logic.

But if g_c_c() always returns the compile-time class of the parent
method, that's a value you already know from inspecting the code. So
the call is likely unnecessary. It could come from cut-and-paste...
things happen. But probably not doing anything that can't be done
without it.

So I'm coming around to agreeing on a necessary BC break.

> Another option is to implicitly promote closures inside of static contexts
> to be also be static; this is basically what HHVM does.

PHP does this! That's why you get 'Cannot bind an instance to a static
closure' if you closure->bindTo() inside a static method, even if the
closure itself is not keyworded static.

The difference between HHVM and PHP is the default class scope of the
closure. PHP makes the decision that the owning class scope of the
closure is the compile-time class of the parent method. Why this was
done I couldn't say.

-- S.









Thread (9 messages)

« previous php.internals (#74120) next »