You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The only way out of this, from the top of my head, is to loop through the input and force-convert every object to an array, but that negates the whole point of using the Hash shorthands, as I can remove what I need to remove in a loop in the first place, and as a bonus, avoid the (likely negligible) cost of parsing the string'{n}.email' at all.
CakePHP Version
5.0.2
PHP Version
8.3.1
The text was updated successfully, but these errors were encountered:
mehov
changed the title
Hash::remove() doesn't work if a child element is not an arrayHash::remove() doesn't work if a child element is an object
Jan 11, 2024
I think expanding the feature set of Hash to handle objects that use a property based protocol is a good idea. The intention for Hash is to be a higher level query/map/reduce toolkit. I think operating on objects fits within those goals. By property based protocol, I'm thinking of a case like
I think expanding the feature set of Hash to handle objects that use a property based protocol is a good idea
That would create inconsistency with other methods like get() and extract() which only support ArrayAccess. So IMO the only change needed here is to include instanceof ArrayAccess along with the is_array() check.
Description
I fetch something from the database, pass it through
Hash::combine()
and I end up with an array of entities.If I call
Hash::remove()
on it, nothing gets removed.I looked through
Hash::remove()
source and I think this is due to theis_array($v)
check here:cakephp/src/Utility/Hash.php
Line 416 in cc93110
When I do
debug(is_array($v))
, I get false, anddebug(\gettype($v))
outputsobject
.So because the above is
false
, it continues toelseif
where$nextPath === ''
also evaluates tofalse
since$nextPath
is in this case'email'
:cakephp/src/Utility/Hash.php
Line 431 in cc93110
As a result, nothing happens.
Is this the intended behaviour?
The only way out of this, from the top of my head, is to loop through the input and force-convert every object to an array, but that negates the whole point of using the
Hash
shorthands, as I can remove what I need to remove in a loop in the first place, and as a bonus, avoid the (likely negligible) cost of parsing the string'{n}.email'
at all.CakePHP Version
5.0.2
PHP Version
8.3.1
The text was updated successfully, but these errors were encountered: