What:
MediaWiki Codesniffer should enforce that files which are namespaced and use array_key_exists() include the following import near the top of the file:
use function array_key_exists;
Why:
Without this, a call to array_key_exists() within a file in e.g. namespace MediaWiki\Config is ambiguous between \MediaWiki\Config\array_key_exists(), \MediaWiki\array_key_exists() and \array_key_exists(); in theory PHP has to check each time the function is called whether the former two functions exist before calling the latter, built-in function, as the namespaced functions may be defined at any time during program execution. (I don’t know if PHP does something smart like tracking an assumption that the namespaced functions don’t exist, and invalidating that assumption when they’re defined; my guess is it doesn’t.) By declaring that we mean the unnamespaced function at the beginning of the file, we skip this lookup everywhere. (This is true for any PHP function we call from namespaced files.)
Furthermore, array_key_exists() in particular has an opcode (ZEND_ARRAY_KEY_EXISTS; merged commit 1, 2) that can be saved in the opcache instead of a generic function call instruction, further optimizing the call; this is also only possible if it’s known at compile time (syntactically) that the call must refer to the unnamespaced, built-in PHP function.
See also SiteConfiguration: Use \array_key_exists() and SiteConfiguration: Use 'use function' syntax for more discussion.
Open questions:
Which functions should we enforce this for? zend_try_compile_special_func_ex has a list of special-cased functions (currently 15), from strlen() to clone(); all of those? Fewer than that? More than that?
Should we enforce this in all MediaWiki codebases, or should the rule be disabled by default (but available in the plugin), to be enabled via .phpcs.xml for specific files or directories thought to contain “hot” code?
Should we enforce this in all files, even unnamespaced ones, so that moving a file to a namespace won’t include a seemingly unrelated use function diff?