phpphpstorm

Can't resolve target of expression 'str_replace('\\', '/', realpath(dirname(__FILE__)))/system/initialize.php'


This is what I have in my config file:

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/

I include the above file in my index file and then include a file initialize.php like

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';

The initialize.php conducts a few checks and sets a few parameters required by the application.

This works fine but recently I switched to PhpStorm and the IDE says

Can't resolve target of expression 'str_replace('\\', '/', realpath(dirname(__FILE__)))/system/initialize.php' (at line 27).

What is this problem? and if the target of expression isn't resolved, as per the IDE, how is it still including the initialize file.


Solution

    1. The warning you see is just an IDE warning, it doesn't cause any problem. The IDE can not get to know what files you want to include because the expression is too complicated.

    2. IDE usually scans all PHP files in your project. so even if the include/require are not parsed correctly, the IDE still knows all the classes/functions in all your PHP files.