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

PHP 8.1RC5: Cannot instantiate enum testEnum when serializing closure that uses an native enum

henze-housepedia opened this issue · comments

  • 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;