On Thu, 13 Apr 2023 at 07:30, Robert Landers <landers.rob...@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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to