"""Checking whether an array is empty with a strict comparison against the empty array is a common pattern in PHP. A GitHub search for "=== []" language:PHP reveals 44k hits. From the set of !$a, count($a) === 0, empty($a) and $a === [] it however is also the slowest option."""

https://github.com/php/php-src/pull/18571

This is a great example of how you should write whatever you find most readable and maintainable, and let us worry about efficiency. Wtih this PR, the "slow" approach becomes a "fast" one.

zend_vm: Add OPcode specialization for `=== []` by TimWolla · Pull Request #18571 · php/php-src

Checking whether an array is empty with a strict comparison against the empty array is a common pattern in PHP. A GitHub search for "=== []" language:PHP reveals 44k hits. From the set of...

GitHub
@pollita This is great! I’ve been using `=== []` because logic dictates it should be faster than a function call (i.e., `count($a) === 0`). I had no idea it was the slower option.
@ramsey Count is usually not a function call, it's a dedicated opcode
@nielsdos @ramsey Within namespaces it's important to point out that this optimization only happens with fully-qualifying the call to `count()`. Either as `\count()` or via `use function count;`. Otherwise a `count()` function could exist in the namespace.
@timwolla True. Which makes me wonder whether it makes sense to emit a JMP_FRAMELESS opcode, not to call these functions framelessly, but to try to use the dedicated op anyway. Maybe I should try this
@nielsdos @timwolla Isn't the problem the fallback to global namespace the problem? As I'm not really sure how you will be able to get from the opcode that does this to the call one being frameless
@Girgias @timwolla The idea is to do something like this (in pseudocode):
01 JMP_FRAMELESS 04 string("foo\\strlen")
... etc
02 V0 = DO_FCALL_BY_NAME
03 JMP 05
04 V0 = COUNT ...
05 Do something with V0