Re: [RFC] Partial Function Application, take 2
| From: | Larry Garfield | Date: | Thu, 10 Jun 2021 14:33:57 +0000 |
| Subject: | Re: [RFC] Partial Function Application, take 2 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-114813@lists.php.net to get a copy of this message | ||
On Thu, Jun 10, 2021, at 3:17 AM, Guilliam Xavier wrote:
> On Wed, Jun 2, 2021 at 7:47 PM Larry Garfield <larry@garfieldtech.com>
> wrote:
>
> > Hi folks. After much off-list discussion, iteration, and consideration,
> > we have a new draft of PFA ready for review.
> >
> > The URL is the same:
> >
> > https://wiki.php.net/rfc/partial_function_application
> >
>
> Hi, thanks all for the reworks! I just thought to something: does it
> support nullsafe calls, e.g.
$foo?->bar(?)? and if yes, what
> is the
> signature of the Closure when $foo === null (and does it make a
> difference if, inside a function, it was created as a local variable `$foo
> = null; vs received as a typed parameter ?Foo $foo`)?
I just checked, and it... sort of supports nullsafe. Rather, if you try to partial a method on a
null object, you get null back for your closure. Then when you try to call it, you get a
"cannot invoke null" error. Which... I think makes sense.
cf: https://3v4l.org/4XeB3/rfc#focus=rfc.partials
As a cute side effect, Joe pointed out you could do this:
https://3v4l.org/ERRdY/rfc#focus=rfc.partials
I wouldn't really call that a feature, but more of a side effect of the implementation. Please
don't count on that behavior.
I also discovered while checking that nullsafe differentiates between null and undefined. That was
unexpected, but not related to the topic at hand. :-)
> Related, for $null === null, is $c =
> $null->bar(?); / `$c =
> $null::baz(?); an immediate error, or only later when calling
> $c($arg)`?
That dies with "call to member function on null" when trying to create the partial:
https://3v4l.org/E6MgK/rfc#focus=rfc.partials
--Larry Garfield