Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace resolution missing for named parameter during serialization #66

Closed
flavioheleno opened this issue Jun 14, 2023 · 6 comments
Closed

Comments

@flavioheleno
Copy link

Serializable Closure Version

1.3.0

PHP Version

8.2.7

Description

Hi, I've hit an issue that I think may be a bug.
I previously thought it was was an issue in PHP-DI, but during my investigation I isolated it to this library (original report here: PHP-DI/PHP-DI#855).
Long story short: if a closure uses a combination of named parameters and a class that is not in the global namespace, it fails when the closure is unserialized.

Steps To Reproduce

// class.php
namespace My\Name\Space;
class MyClass {
  public const A = 1;

  public function __construct(string $arg1, int $arg2) {}
}
// main.php
require_once __DIR__ . '/vendor/autoload.php';
include __DIR__ . '/class.php';

use Laravel\SerializableClosure\UnsignedSerializableClosure;
use My\Name\Space\MyClass;

$closure = static function (): MyClass {
  return new MyClass(arg2: MyClass::A);
};

$s = serialize(new UnsignedSerializableClosure($closure));
var_dump(unserialize($s)->getClosure()());
$ php main.php 
PHP Fatal error:  Uncaught Error: Class "MyClass" not found in laravel-serializable-closure://static function (): \My\Name\Space\MyClass {
  return new \My\Name\Space\MyClass(arg2: MyClass::A);
}:3
Stack trace:
#0 /home/flavio/Documents/open-source/serialize-bug/main.php(14): {closure}()
#1 {main}
  thrown in laravel-serializable-closure://static function (): \My\Name\Space\MyClass {
  return new \My\Name\Space\MyClass(arg2: MyClass::A);
} on line 3
@driesvints
Copy link
Member

Heya, thanks for reporting.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@nunomaduro
Copy link
Member

Actually, would be even better create a pull request with a failing test.

@flavioheleno
Copy link
Author

Hey, I have a failing test that I was using to investigate, what should I do, follow @driesvints or @nunomaduro ?

@driesvints
Copy link
Member

feel free to send in a draft pr with the failing test 👍

@flavioheleno
Copy link
Author

@driesvints just did in #67 please let me know what else can I do to help :-)

@driesvints
Copy link
Member

cool, thanks. Closing this now. Let's continue on the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants