3

With PHP, static method can be used in both static method and non-static method, and non-static method can only used in non-static method. That's why calling a dynamic method statically generates the E_STRICT error.

For example:

<?php

class Example
{
    public function foo() {
        return "Foo";
    }

    public static function bar() {
        return "Bar";
    }
}

$ex = new Example();

// Non-static call
echo $ex->bar();

// Static call on a non-static method
// PHP Error "Strict standards: Non-static method should not be called statically"
// ERROR NOT DETECTED BY PHPSTORM!
echo Example::foo();

The last line will generated this PHP error (it's logic): enter image description here

I am currently working on a large PHP application that calls, in some PHP files, non-static methods statically. It was not a problem with an very old version of PHP but we have decided to migrate to the latest PHP version.

Manually check all the project files to identify this bad syntax will be too long (+ 1000 files)!

The built-in code inspection features of PhpStorm doesn't detect this type of error within the analyzed source code. Why? Should I configure something? How?

Below, my PHP code inspection configuration in PhpStorm:

enter image description here

Thanks!

4

3 回答 3

5

该检查在这里工作正常(证明)。

  1. 请尝试Code | Inspect Code...这个文件——它会强制从头开始重新分析这个文件。好点?

  2. 如果没有 - 请执行File | Invalidate Caches...并重新启动 IDE


PS
如果您有兴趣仅在整个项目上运行此检查- 使用-对每个文件Code | Run Inspection by Name... 进行完整检查要快得多。Inspect Code

于 2015-11-27T10:31:57.333 回答
1

静态代码分析可能会提示一些潜在的错误。它从不保证没有错误,人们真的不应该依赖它。

作为一个实用的建议,您可以使用类似的东西搜索所有静态调用

grep -roh "\w\+::.\+\?("

并自己分析列表。

于 2015-11-27T10:22:24.013 回答
0

更改 php.ini 文件中的错误报告

error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED

于 2016-01-07T11:09:37.703 回答