On Fri, Jul 2, 2021 at 10:32 AM Ralph Schindler
<[email protected]> 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.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php