I’d like to know whether simply using PHP’s error suppression syntax is a faster and simpler alternative to array_key_exists where it is not certain that a particular key exists.
That is, instead of:
if (array_key_exists($array, $key)) {
$myval = $array[$key];
[... do something with $myval ...]
}
Simply use:
if ($myval = @$array[$key]) {
[... do something with $myval ...]
}
Seems like this is both more efficient and less wordy, but perhaps it introduces subtle problems or edge-cases that I’m not seeing yet.
What are the potential problems with this approach?
BTW you can also use
isset().The error suppression operator in PHP also slows it down a lot, to about half the usual speed.
And finally you will eventually run into a case where you are supressing errors, and discover that you typoed and
$araydoesn’t exist either, which you will never even find out since you are blocking all errors.