Searching for documentation on this is nigh-futile as search engines seem to assume I'm asking about the &&
operand. What I found on PHP.net, touches on its use as an operand but I'm still unclear as to how it is working in a code snippet I ran across.
! empty( $foo )
and $bar .= 'string';
I think I understand that to be something akin to:
if ( ! empty( $foo ) ){
$bar .= 'string';
}
But it doesn't seem to be a bracket-less if
conditional (it breaks if I remove the and
).
I should say that I do – or thought I did – understand how &&
an and
would work in the context of a comparison. It is the use of it on its own line (partially) and that the $bar .= 'string'
is not a test condition that prompted the question.
Updated
What I understand from the discussion in the comments is as follows:
If ! empty( $foo )
were to be false
, it would short-circuit the operation; anything beyond the and
would not be evaluated.
The and
is still simply fulfilling its role as a comparison operator(?). In this usage, the $bar .= 'string'
side of the and
is not another test condition… or is it? Is it evaluating whether $bar
is truthy (which, in PHP, it seems to be whether $bar
was declared/defined beforehand or not), then continuing on to concatenate string
to it?