Undefined variable when using empty function

I need a warning when a undefined variable is used in empty function. Is there any way to solve this?

3 comments

Hi there,

You can start with providing some sample code.

It should also tell what language it is (PHP/JavaScript etc)

E.g. in this PHP code $number variable is highlighted correctly (difference is: this function is not "empty" as per your subject):

function tt()
{
    $aa = 3 * $number;
    
    return $aa;
}

 

1

Thank you for replying.

Like this in php.

function test() {

    if(!empty($aa)) {

         echo 111;

    }

}

 

the code $aa variable is not highlighted. In code refactoring, I often forget to pass a parameter .

The problem is that empty function is not working . 

0

Accordingly to PHP documentation there is nothing wrong with the code above .. as it's how empty() works:

>Determine whether a variable is considered to be empty. A variable is considered empty if it does not exist or if its value equals FALSE. empty() does not generate a warning if the variable does not exist.

 

In any case -- please install "Php Inspections (EA Extended)" plugin -- it provides inspection that will issue a warning for your code.

1

Please sign in to leave a comment.