PHP 8.4.24 Released!

Voting

: min(one, seven)?
(Example: nine)

The Note You're Voting On

georgy dot moshkin at techsponsor dot io
2 years ago
Left-to-right evaluation of && operators has one useful feature: evaluation stops after first "false" operand is encountered.
 
This feature can be useful for creating following construction:

$someVar==123 is not evaluated, so there will be no warnings such as "Undefined variable $someVar":
<?php
// $someVar=123; - commented line
if ((!empty($someVar))&&($someVar==123))
{
    echo $someVar;
}
?>

Function someFunc($someVar) will not be called:
<?php
// $someVar=123; - commented line
if ((!empty($someVar))&&(someFunc($someVar)))
{
    echo $someVar;
}
?>

This will give "Warning: Undefined variable $someVar" error. Order matters:
<?php
// $someVar=123;
if ((someFunc($someVar))&&(!empty($someVar)))
{
    echo $someVar;
}
?>

<< Back to user notes page

To Top