Re: First class callable syntax for instance methods

From: Date: Thu, 13 Apr 2023 13:47:28 +0000
Subject: Re: First class callable syntax for instance methods
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-120027@lists.php.net to get a copy of this message
On Thu, 13 Apr 2023 at 07:30, Robert Landers <landers.robert@gmail.com> wrote: > > This has been brought up a couple of times, but I can't seem to find > it. https://externals.io/message/119392 https://externals.io/message/120011 > I don't think something like this is possible with the current > implementation of first-class-callables (it would need a major > refactor). It's not currently possible, but it wouldn't need a huge refactor...we could just do what Java does: https://www.baeldung.com/java-method-references https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html // If we copied the Java way of doing it, this: // $fn = Verification::getId(...); // $fn would be equivalent to: $fn = fn (Verification $v) => $v->getId(); And if the method of the class has parameters, those would be after the first instance parameter: class Foo { function bar(int $x) {} } $fn = Foo::bar(...); // Would be equivalent to: $fn = fn (Foo $f, int $x) => $f->bar($x); I can't see a technical reason not to do it like this, but some people seem to be having negative gut reactions to it, and it's hard to persuade someone about aesthetics. Notes here: https://phpopendocs.com/rfc_codex/class_method_callable cheers Dan Ack

« previous php.internals (#120027) next »