DEV Community

loading...

Discussion on: Using isset() and empty() hurts your code

Collapse
dhandspikerwade profile image
Devin Handspiker-Wade

The issue is when working with large arrays or being called frequently, array_key_exists is 2x to 10x slower than isset.

Collapse
arturm11 profile image
arturm11

Already fixed in 7.4

Collapse
dhandspikerwade profile image
Devin Handspiker-Wade

Interesting! Might need to give 7.4 a look sooner than expected.

Collapse
aleksikauppila profile image
Aleksi Kauppila Author

Interesting, thanks! Do you have a benchmark available somewhere?

Collapse
dhandspikerwade profile image
Devin Handspiker-Wade • Edited

It's a simple benchmark with many examples, but to quote one of them provided on the PHP manual:

Benchmark (100000 runs):
array_key_exists() : 205 ms
is_set() : 35ms
isset() || array_key_exists() : 48ms
Enter fullscreen mode Exit fullscreen mode