Skip to content

Conversation

@godismyjudge95
Copy link
Contributor

Tricky behavior ran into by Erin - https://discord.com/channels/489818810157891584/489830535565148169/1333967156861468694

This won't directly solve what he was dealing with (as he had a custom class), but it will fix it for future devs checking if a property on a Value is empty.

Currently, if you have an object wrapped by a Value and then check the emptiness of a property on that object it returns true no matter what:

image

This is due to https://www.php.net/manual/en/function.empty.php#99959

Calling non existing object property, empty($object->prop), will trigger __isset(), the same way as isset($object->prop) does, but there is one difference. If __isset() returns TRUE, another call to __get() will be made and actual return value will be result of empty() and result of __get().

In other words, since Value doesn't have the __isset() method on it every single empty() check on a property inside of it will fail.

This PR fixes that and adds a test :)

@jasonvarga jasonvarga merged commit 212bb52 into statamic:5.x Feb 18, 2025
18 checks passed
@godismyjudge95 godismyjudge95 deleted the fix-empty-value-check branch August 15, 2025 16: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.

2 participants