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

[3.x] Fix conflicts with PHP's predefined classes #8253

Conversation

PerryvanderMeer
Copy link
Contributor

This PR fixes the problem described in discussion #8248.

Problem

When you have a component in Livewire's root class namespace that matches any of PHP's predefined classes, subsequent requests won't work.

So, an initial request for the component App\Livewire\Directory works, but subsequent requests won't. Those will trigger Livewire's ComponentNotFoundException:

Unable to find component: [directory]

Note: when the component is located as App\Livewire\Foo\Directory, also subsequent requests will work.

Cause

For subsequent requests, Livewire will try to resolve the requested component's location.
Initially, it will check if a class exists for the requested component:

if (class_exists($nameOrClass)) {

For App\Livewire\Directory (which will be requested as directory), this will return true, because class_exists('directory') returns true as it matches PHP's predefined class. Note: that is also the explanation why locating App\Livewire\Foo\Directory works, because class_exists('foo.directory') won't conflict.

Solution

We can extend the class existance-check with a check if the found class also extends Livewire's Component class. Obviously PHP's predefined class does not comply with that, while App\Livewire\Directory will.

@calebporzio
Copy link
Collaborator

Ahhhhh that's a tricky one, I think I was actually bit by this recently. Thanks! (and thanks for the super clear PR writeup!)

@calebporzio calebporzio merged commit 24a8ed7 into livewire:main Apr 5, 2024
5 checks passed
@PerryvanderMeer PerryvanderMeer deleted the fix-conflicts-with-predefined-classes branch April 5, 2024 13:36
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.

None yet

2 participants