Does PHP have short-circuit evaluation?

Yes, the PHP interpreter is “lazy”, meaning it will do the minimum number of comparisons possible to evaluate conditions.

If you want to verify that, try this:

function saySomething()
{
    echo 'hi!';
    return true;
}

if (false && saySomething())
{
    echo 'statement evaluated to true';
}

Leave a Comment