mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix Hash type casting
When using comparison with a boolean, as the filter is a string, we have to convert the data boolean to "boolean string" to avoid type-casting troubles. ## Example ```php $users = [ [ 'id' => 2, 'username' => 'johndoe', 'active' => true ], [ 'id' => 5, 'username' => 'kevin', 'active' => true ], [ 'id' => 9, 'username' => 'samantha', 'active' => false ], ]; $unactiveUsers = Hash::extract($users, '{n}[active=false]'); print_r($unactiveUsers); ``` This example returns the two unwanted active users because `"false"` is `true` but not `false` :) I think this pull request will fix this issue by converting true/false boolean to string (to match with our filter).
This commit is contained in:
parent
f9a6c1905b
commit
db450a96e9
1 changed files with 1 additions and 1 deletions
|
@ -192,7 +192,7 @@ class Hash {
|
|||
return false;
|
||||
}
|
||||
|
||||
$prop = isset($data[$attr]) ? $data[$attr] : null;
|
||||
$prop = isset($data[$attr]) ? ( is_bool($data[$attr]) ? (($data[$attr]) ? 'true' : 'false') : $data[$attr] ) : null;
|
||||
|
||||
// Pattern matches and other operators.
|
||||
if ($op === '=' && $val && $val[0] === '/') {
|
||||
|
|
Loading…
Reference in a new issue