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

Result in syntax error when serializing instanceof {expression} #104

Draft
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

ralphjsmit
Copy link

@ralphjsmit ralphjsmit commented Jan 22, 2025

Hello, I noticed that when serializing any instanceof with the result being an expression fails.

For example, code that fails is:

$this instanceof (Foo::class)

Practical example:

if ($this instanceof (class_exists(Foo::class) ? Foo::class : Bar::class)) {}

This type of code gets compiled into:

fn (\Foo\Bar $a) => $this instanceof \Foo\Bar (\Foo\Baz\Qux\Forest::class)

Basically, it seems like the serializable closure takes the last class that it replaced/imported the full namespace for, and puts it after the instanceof and before the expression, thus resulting in this syntax error: $this instanceof \Foo\Bar (...).

I first added a failing test to identify it. Then I looked into if I could pinpoint the issue, but unfortunately I did not find it myself. If someone with good knowledge of this could pinpoint me to the correct place where to make the fix would be awesome. Also, feel free to take over the PR.

Thanks!

@schaper1337
Copy link

Good find :)

@taylorotwell taylorotwell marked this pull request as draft January 22, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants