Issue
Whats the best way to do a regex search and replace for all instances of array_key_exists()
with the more efficient isset()
? Please, no Donald Knuth quotes regarding optimizations and yes, I'm aware of the href="https://stackoverflow.com/a/3210982/3306354">differences between the two functions.
This is what I'm currently using in my Netbeans search and replace:
search for:
array_key_exists\s*\(\s*'([^']*)'\s*,([^)]*)\)
replace with:
isset($2['$1'])
it works well , changing this:
array_key_exists('my_key',$my_array)
to
isset($my_array['my_key'])
but doesn't pick up instances like this:
array_key_exists($my_key,$my_array)
Solution
The best I could do was to run a second search and replace to cover the instances that used variables for both arguments:
array_key_exists($my_key,$my_array)
search and replace 2:
search for:
array_key_exists\s*\(\s*(\$[^,]*)\s*,([^)]*)\)
replace with:
isset($2[$1])
Answered By - AndrewD
Answer Checked By - Robin (JavaFixing Admin)