PHP: Lint/Find silent string to array conversions

I have to maintain old code (mainly written in PHP 5.3) and we are trying to raise it to PHP 7.2.

So far we are going well but I have a problem with silent string to array conversions.

What I mean is initializing a variable as an empty string and then use it as an array:

$test = "";

$test[] = "foo";

This will work in older PHP version but since 7.1 will raise a fatal exception.

Is there a way, say a linter, with which i can scan the code for this kind of usage to get a list where i have to change the initialization of the variables? The application is huge so it would be a pain to do it manually...

728x90

1 Answers PHP: Lint/Find silent string to array conversions

Try list files and string.

grep -nr '"";' .

IF ok, exchange

grep -lr '"";' . | xargs perl -p -i -e 's/"";/array();/g'

1 months ago