Support the ongoing development of Laravel.io →
posted 1 year ago
Laravel
0
moderator

Hello @leenooks

This is default functionality for PHP, see: https://www.php.net/manual/en/language.oop5.overloading.php

The most important part is:

__isset() is triggered by calling isset() or empty() on inaccessible (protected or private) or non-existing properties.

It doesn't load execute a __GET() to only see if the variable is set.

So in basic: If you implement the __GET() function it is advisable to implement the __ISSET function.

0

You are right that the issue is rooted in the isset() method. The isset() method only checks for the existence of a public property or a public variable. If the attribute is accessed via the __get() method, the isset() method will not be able to detect it.

The workaround you mentioned is correct. You can create an __isset() method on the object to return true if the attribute is accessible via __get(). This will allow the pluck method to work correctly, even if the attribute is accessed via __get().

I agree that this is a shortcoming in Laravel. The pluck method should be able to check if an attribute is accessible via __get(), even if it is not defined as a public property.

I also think that the __isset() method is a good workaround. It is simple to implement and it works reliably. I would recommend using this workaround until the Laravel team fixes the issue.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Deon George leenooks Joined 19 Aug 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.