1

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...

1 Answer 1

2

Try list files and string.

grep -nr '"";' .

IF ok, exchange

grep -lr '"";' . | xargs perl -p -i -e 's/"";/array();/g'
2
  • 1
    Well, yes, that gave me 559 lines where a variable with an empty string is defined... still a lot to check but a step in the right direction... Still many many false positives in the list. Many variables that are not used as array after string declaration
    – pyriand3r
    Feb 11, 2019 at 10:22
  • After all we used the first statement to get an overview and went through the results by hand.
    – pyriand3r
    Apr 30, 2019 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.