atm i want to prepare my code to upgrade from PHP 7.0 to 7.2.
For this i wrote my own small search & replace script which uses REGEX rules to find incompatiblity code and if possible fix them with preg_replace.
Code Error:
"Warning: Use of undefined constant..."
For this i wrote the follow REGEX:
$search_strings['7.0 to 7.2']['search'][] = '#(\[([^0-9$]\w+)\](?!\'))#i';
$search_strings['7.0 to 7.2']['replace'][] = '[\'$2\']';
This works with normal Arrays in code but if they are nested inside a MySQL Query or inside a echo/declaration value it still sucks:
The most rules worked fine, but now i want to fix the follow:
$MyArray[array_level1][] = 'sdfsdf [test] my code';
will replace to(wrong):
$MyArray['array_level1'][] = 'sdfsdf ['test'] my code';
should be:
$MyArray['array_level1'][] = 'sdfsdf [test] my code';
or
$sel = "SELECT * FROM $tbl[my_table_name] WHERE request LIKE '$myArray[test]%' LIMIT 0,1";
will replace to(wrong):
$sel = "SELECT * FROM $tbl['my_table_name'] WHERE request LIKE '$myArray['test']%' LIMIT 0,1";
should be(i think for this is an extra regex needed because to complex?):
$sel = "SELECT * FROM ".$tbl['my_table_name']." WHERE request LIKE '".$myArray['test']."%' LIMIT 0,1";
Which also wrong...i testet several REGEX but didn´t find a solution, i think i need to optimize my negative lookahead, here is my example: