PHP 8.1RC5: Cannot instantiate enum testEnum when serializing closure that uses an native enum
henze-housepedia opened this issue · 0 comments
henze-housepedia commented
- Serializable Closure Version: v1.0.3
- Laravel Version: v8.70.1
- PHP Version: v8.1.0RC5
- Database Driver & Version: not required in this case
Description:
I am currently updating my code to use native enums from PHP 8.1. This package does not support them yet. This is not a bug yet, but it will be when people start using PHP 8.1 which is released on November 25th.
Steps To Reproduce:
Ofcourse have PHP 8.1.0RC5 installed, and run the following script with it
enum testEnum
{
case HELLO;
case WORLD;
}
$enum = testEnum::HELLO;
$closure = function () use ($enum) {
return $enum->name;
};
SerializableClosure::setSecretKey('secret'); // commenting this out gives the same result
$serialized = serialize(new SerializableClosure($closure)); // throws `Cannot instantiate enum testEnum` error here
$closure = unserialize($serialized)->getClosure();
echo $closure(); // HELLO;