serializable-closure icon indicating copy to clipboard operation
serializable-closure copied to clipboard

Crash with closures created from methods with method-only attributes

Open danog opened this issue 9 months ago • 1 comments

Serializable Closure Version

2.0.3

PHP Version

8.4.4

Description

The following fatal error is emitted when serializing closures created from class methods with attributes that can target only methods and not functions.

PHP Fatal error:  Attribute "MyAttribute" cannot target function (allowed targets: method) in laravel-serializable-closure://#[MyAttribute()]
function (): void {
        \var_dump("hello");
    } on line 3

Steps To Reproduce

<?php

use Laravel\SerializableClosure\SerializableClosure;

require 'vendor/autoload.php';

class a {
    public function test(): void {}
}
class b extends a {
    #[\Override]
    public function test(): void {
        var_dump("hello");
    }
}

$a = new SerializableClosure((new b)->test(...));
$a = unserialize(serialize($a));

$a();

danog avatar Mar 07 '25 09:03 danog