Fixed key_exists/fnKeyExists

Xon

Well-known member
Affected version
2.1.10 Patch 2
fnKeyExists calls array_key_exists without checking if $array is an actual array.

According to https://www.php.net/manual/en/function.array-key-exists.php property_exists should be used if $array is an object. And some additional work is probably required if __get or ArrayObject support is desired.

I'm fairly sure this function should return false if the $array argument is neither an array or an object. Or generate an error.
 
Last edited:
While we're at it, array_key_exists has its own opcode as of PHP 7.4, but it only works in namespaced files if the fully-qualified name is used (\array_key_exists) or the function is imported (use function array_key_exists). Probably couldn't hurt to get into the habit of replacing array_key_exists with \array_key_exists in new or modified code that's likely to get called a lot.
 
but it only works in namespaced files if the fully-qualified name is used (\array_key_exists) or the function is imported (use function array_key_exists
.where did you find this information? Can't find anything about it
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.0 Beta 2).

Change log:
Check if the array passed in to fnKeyExists is actually an array before calling array_key_exists
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom