Phpstorm Can';t解析表达式的目标';str#replace(';\\';';/';,realpath(dirname(#uu FILE#))/system/initialize.php';

Phpstorm Can';t解析表达式的目标';str#replace(';\\';';/';,realpath(dirname(#uu FILE#))/system/initialize.php';,phpstorm,Phpstorm,这是我的配置文件中的内容: define('BASE_DIR', str_replace('\\', '/', realpath(dirname(__FILE__))) . '/', false); // output: C:/xampp/htdocs/myweb/ define('BASE_URL', $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/', false

这是我的配置文件中的内容:

define('BASE_DIR', str_replace('\\', '/', realpath(dirname(__FILE__))) . '/', false);
// output: C:/xampp/htdocs/myweb/

define('BASE_URL', $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/', false);
//output: http://localhost/myweb/

define('APP_DIR', BASE_DIR . 'app/', false);
// output: C:/xampp/htdocs/myweb/app/

define('TEMP_DIR', BASE_DIR . 'app/view/template/', false);
//output: C:/xampp/htdocs/myweb/app/view/template/

define('LIBRARY_DIR', BASE_DIR . 'library/', false);
//output: C:/xampp/htdocs/myweb/library/

define('SYSTEM_DIR', BASE_DIR . 'system/', false);
//output: C:/xampp/htdocs/myweb/system/
我将上面的文件包括在索引文件中,然后包括一个类似initialize.php的文件

index.php

// Include the config file. If file not found throw error and exit.
if (!file_exists('config.php')) {
    header('Location: error/404.php');
    exit();
} else {
    include_once 'config.php';
}

// Load startup file to check, set environment plus a few core files
require_once SYSTEM_DIR . 'initialize.php';
php执行一些检查并设置应用程序所需的一些参数

这很好,但最近我切换到PhpStorm,IDE说

无法解析表达式“
”str\u replace(“\\”、“/”、realpath(dirname(\uu FILE\uuu)))/system/initialize.php“
(第27行)的目标

这是什么问题?如果表达式的目标没有按照IDE解析,它如何仍然包含初始化文件

  • 您看到的警告只是一个IDE警告,它不会导致任何问题。IDE无法知道要包含哪些文件,因为表达式太复杂

  • IDE通常扫描项目中的所有PHP文件。因此,即使未正确解析
    include/require
    ,IDE仍然知道所有PHP文件中的所有类/函数

  • 您看到的警告只是一个IDE警告,它不会导致任何问题。IDE无法知道要包含哪些文件,因为表达式太复杂

  • IDE通常扫描项目中的所有PHP文件。因此,即使未正确解析
    include/require
    ,IDE仍然知道所有PHP文件中的所有类/函数


  • 很简单:IDE无法解释
    str\u replace('\\','/',realpath(dirname(\uu FILE\uu)))。/'的最终结果require\u once SYSTEM\u DIR'时,code>为(这是
    BASE\u DIR
    常量的定义)初始化.php'行(检测实际路径)。该常量过于动态,无法处理IDE使用的静态分析。只需禁用检查(检查包含/需要文件的路径)即可消除警告。@LazyOne,谢谢。。。如何接受你的答案?你可以接受shawn的答案,也可以接受合理的解释。很简单:IDE无法解释str\u replace(“\\\”、“/”、realpath(dirname(\uu FILE\uu)))的最终结果。/require\u once SYSTEM\u DIR'时,code>为(这是
    BASE\u DIR
    常量的定义)初始化.php'行(检测实际路径)。该常量过于动态,无法处理IDE使用的静态分析。只需禁用检查(检查包含/需要文件的路径)即可消除警告。@LazyOne,谢谢。。。如何接受你的答案?你可以接受肖恩的答案——还有像样的解释。