phpstan / phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
MIT License
595 stars 46 forks source link

Use of compersion operatore in some functions #180

Closed StefanoTesla closed 2 years ago

StefanoTesla commented 2 years ago

Many days ago my code was:

        if (strpos($result, "\\n",0) > 0){

            $result = str_replace("\\n","",$result);

        }

Testing on PHPStan I get error on the > 0 and at today I cannot replicate, but the error seggested to me that strpos can return 0 or false and the > 0 comparsion was not very good.

In the same day I tried olso:

        if (strpos($result, "\\n",0) <> false){

            $result = str_replace("\\n","",$result);

        }

And I didn't get any error but the right way is

        if (strpos($result, "\\n",0) !== false){

            $result = str_replace("\\n","",$result);

        }

The most strange thing, is at today I cannot see the error message (I'm testing with the online editor)

ondrejmirtes commented 2 years ago

I don't think that these code snippets ever returned an error. strpos returns int|false.

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.