Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

IDE saying the variables is unused and undefined

The IDE in functions.php $result; will either tell me that the variable is undefined, and if I change it to $result = null; the IDE will tell me that it is an unused variable.

Why does this happen?

This underlines in PHPStorm as undefined variable:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function emptyInputSignup($name, $email, $username, $pwd, $pwdRepeat)
{

    $result;
    if (empty($name) || empty($email) || empty($username) || empty($pwd) || empty($pwdRepeat)) {
        $result = true;
    } else {
        $result = false;
    }
    return $result;
}

This underlines in PHPStorm as unused variable:

function emptyInputSignup($name, $email, $username, $pwd, $pwdRepeat)
{

    $result = null;
    if (empty($name) || empty($email) || empty($username) || empty($pwd) || empty($pwdRepeat)) {
        $result = true;
    } else {
        $result = false;
    }
    return $result;
}

>Solution :

I guess your IDE is frowning because, for instance :

$result;
if (empty($name) || empty($email) || empty($username) || empty($pwd) || empty($pwdRepeat)) {
    $result = true;
} else {
    $result = false;
}
return $result;

Could easily be replaced by :

if (empty($name) || empty($email) || empty($username) || empty($pwd) || empty($pwdRepeat)) {
    return true;
}
return false;

So the use of a $result variable is indeed moot.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading