laravel / serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using php's 8.1 first class callable method leaves an xdebug in limbo

tschallacka opened this issue · comments

When a closure is passed via a first class callable method xdebug doesn't know where it is.

<?php
namespace Foo;
include_once '/path/to/laravel/vendor/autoload.php';

use Laravel\SerializableClosure\SerializableClosure;

class Bar {
    public function __construct(public int $x = 0) {

    }

    public function foo(int $a) {
        $y = $a + $this->x;
        xdebug_break();
    }
}

$bar = new Bar();
$closure = new SerializableClosure($bar->foo(...));
$x = serialize($closure);
echo $x;
$z = unserialize($x);
$z->getClosure()(2);

image

When a closure is passed via a first class callable method, maybe serialize the given class, then call the method on the deserialized class?
Currently we need to use string references instead of these first class callable features we have now available.

Please recreate this issue with a filled out issue template. Thanks