Skip to content

Commit

Permalink
Merge pull request #19 from laravel/fix/rebound-closures
Browse files Browse the repository at this point in the history
[1.x] Fixes rebound closures serialization
  • Loading branch information
taylorotwell authored Sep 29, 2021
2 parents 20333bb + 5133d74 commit 11e5e1b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Serializers/Native.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 11e5e1b

Please sign in to comment.