Skip to content

Fixed error "method_exists(): Argument #1 ($object_or_class) must be of type object|string, array given" when using Livewire and AdminLTE. #524

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

Merged
merged 2 commits into from
Mar 24, 2025

Conversation

JA-Developer
Copy link
Contributor

I made the changes mentioned in the issue #517. That the exception "method_exists(): Argument #1 ($object_or_class) must be of type object|string, array given" from being thrown.

… must be of type object|string, array given' when using Darryldecode\Cart\Cart.
@gwleuverink
Copy link
Contributor

Hi @JA-Developer. Thanks so much for your PR 🙏

Perfect, I think this check makes sense here. We only want to handle events that are broadcasted on the NativePHP channel here, and return as early as possible if it is not.

Could you perhaps update this to an return clause with is_object? We think this is slightly more legible by anvoiding any unnecessary casting.

@JA-Developer
Copy link
Contributor Author

Yes. I made the changes you asked for,
Thank you for giving me your feedback.

Copy link
Contributor

@gwleuverink gwleuverink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@simonhamp simonhamp requested a review from a team March 24, 2025 12:15
Copy link
Member

@PeteBishwhip PeteBishwhip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, but all-in-all a great addition to help us bail early.

Thank you for your contribution! :)

if(! is_object($event)) {
return;
}

if (! method_exists($event, 'broadcastOn')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following would have sufficed as conditionals are evaluated in order and reduced the need for an additional return clause however, the above works too. Thanks!

Suggested change
if (! method_exists($event, 'broadcastOn')) {
if (!is_object($event) || ! method_exists($event, 'broadcastOn')) {

@PeteBishwhip PeteBishwhip merged commit 6899c2c into NativePHP:main Mar 24, 2025
42 of 43 checks passed
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