Re: [VOTE] First-class callable syntax

From: Date: Fri, 02 Jul 2021 22:21:14 +0000
Subject: Re: [VOTE] First-class callable syntax
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-115279@lists.php.net to get a copy of this message
On Fri, Jul 2, 2021 at 10:32 AM Ralph Schindler <ralph@ralphschindler.com> wrote: > > > > This RFC uses a syntax that is forward-compatible with partial function > > application. Should it not be accepted, I'll explore alternative syntax > > possibilities. > > Given the choice of syntax in this proposal (which I do like)... Is the > following (potentially future) use case precluded by the syntax (whether > or not you like it immediately ;) )? > > Basically be able to: > > 1. be able to refer to an instance method statically (this is currently > an error) > > 2. allow late binding of $this/context/closure scope, either via > bindTo() or via Reflection setClosureThis() (does not exist) > > > > class MyController { > public function myAction($name) { > return new Response("Hello, $name"); > } > } > > // Closure with no $this (to be filled in later) > $fn = MyController->myAction(...); > > > $controller = new MyController; > $response = ($fn->bindTo($controller))($params); It would theoretically be: $fn = MyController::myAction(...); It currently errors: > Fatal error: Uncaught Error: Non-static method MyController::myAction() cannot be called > statically I would be okay with allowing this, as long as it's bound before it's called.

« previous php.internals (#115279) next »