diff --git a/src/Serializers/Native.php b/src/Serializers/Native.php index bbea9285..95916681 100644 --- a/src/Serializers/Native.php +++ b/src/Serializers/Native.php @@ -210,7 +210,7 @@ public function __unserialize($data) public static function wrapClosures(&$data, $storage) { if ($data instanceof Closure) { - $data = static::from($data); + $data = new static($data); } elseif (is_array($data)) { if (isset($data[self::ARRAY_RECURSIVE_KEY])) { return; diff --git a/tests/SerializerTest.php b/tests/SerializerTest.php index e40d8962..378e6cb4 100644 --- a/tests/SerializerTest.php +++ b/tests/SerializerTest.php @@ -367,6 +367,23 @@ function () { expect($r)->toEqual('Hi'); })->with('serializers'); +test('rebound closure', function () { + $closure = Closure::bind( + function () { + return $this->hello(); + }, + new A3(function () { + return 'Hi'; + }), + A3::class + ); + + $u = s($closure); + $r = $u(); + + expect($r)->toEqual('Hi'); +})->with('serializers'); + class A { protected static function aStaticProtected() @@ -422,6 +439,21 @@ public function getEquality() } } +class A3 +{ + private $closure; + + public function __construct($closure) + { + $this->closure = $closure; + } + + public function hello() + { + return ($this->closure)(); + } +} + class ObjSelf { public $o;