Some inspector Questions

Hi,

I am new on PHPStorm and it looks very nice. But I get some validation warnings and errors, which I dont know how to correct them.

1)

I have a config.php script which includes a localize.php script. In this localize.php script I setup a global variable $dateformat.
Any time I use this variable in my scripts I get an undefined varabile error.
How can I fix this?

2)

I create a sql statement programmatically. for Example:

        $sql = "SELECT `bug_id`,`bug_date`,`bug_priority`,`bug_description`,`bug_status`,ge_user.user_lastname AS bug_user,
                    CASE bug_status
                        WHEN 0 THEN 'New'
                        WHEN 1 THEN 'Assigned'
                        WHEN 2 THEN 'Fixed'
                    END AS bug_status
                FROM ge_bug
                INNER JOIN ge_user ON (ge_user.user_id=ge_bug.bug_user)
                $sWhere";


in $sWhere can be "" to get all bugs, as well as something like "HAVING..." So it's not a bug. But PHPStorm tells me it is.
What can I do?

3)

I have the following construct:

    if(isset($_SESSION['currentDir']))
    {
        include_once($_SESSION['currentDir']. "/ge_localize.php");
    }

PHPStorm gives me an "PAth ge_localize.php not found" waarning.
How can I fix this?

Thanks

Claus
2 comments
Comment actions Permalink

Hi there,

1) Assign proper typehint to it via PHPDoc + declare it as global, something like this:

/** @var string $dateformat */

global $dateformat;



2) No much you can do right now without changing the actual string. Thing is -- SQL command gets verified AS IS against selected SQL Dialect (MySQL, SQL Server etc). Obviously that $sWhere (the way how it is used in that string) is not a valid SQL.

Follow this ticket (and related) to see the progress made in this regard: http://youtrack.jetbrains.com/issue/WI-2450

Right now you can:

a) (the easiest) Set SQL Dialect to "Keywords Only" -- no SQL Inspections will be run -- only generic syntax highlighting
b) Rewrite the query a tiny bit (in this particular example it's just a bit) to use concatenation. Unfortunately, you will loose syntax highlighting in such case -- http://youtrack.jetbrains.com/issue/WI-534

$sql = "SELECT `bug_id`,`bug_date`,`bug_priority`,`bug_description`,`bug_status`,ge_user.user_lastname AS bug_user,
    CASE bug_status
        WHEN 0 THEN 'New'
        WHEN 1 THEN 'Assigned'
        WHEN 2 THEN 'Fixed'
    END AS bug_status FROM ge_bug INNER JOIN ge_user ON (ge_user.user_id=ge_bug.bug_user) " . $sWhere;



3) Few options:

a) Disable that inspection completely ("Settings | Inspections | PHP | General | Unresolved Include"). Since PhpStorm has no idea (and no way to know for sure) what the value of $_SESSION['currentDir'] is, it cannot reliably verify the file path, hence the warning.
b) Suppress inspection warnign for THAT line/statement ONLY -- Alt+Enter (or click on Light Bulb icon) while cursor standing on the warning and choose "Suppress for statement" from submenu:
screen01.png

0
Comment actions Permalink

Hi Andríy

thanks for your help.

Regards

Claus

0

Please sign in to leave a comment.