Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP short circuit lazy evaluation, where is it in the php.net manual?

Sorry if this sounds like a really silly question.

But I Googled the web and also Googled specifically both the php.net site and the stackoverflow.com site. I know PHP does short circuit lazy evaluation when using and, or, &&, || operators, but where is it stated loud and clear in the PHP manual???

I found only Wikipedia as the only 'trusted' source that say PHP does lazy evaluation on these operators.

like image 946
Marco Demaio Avatar asked Jul 10 '10 21:07

Marco Demaio


People also ask

Does PHP have short circuit?

You are speaking about operators and I speaking about gates, in PHP both operators are an AND gate, but one is short circuited.

What is short circuit evaluation in context of&& and|| operators?

Short-circuit evaluation, minimal evaluation, or McCarthy evaluation (after John McCarthy) is the semantics of some Boolean operators in some programming languages in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression: when the first ...

What is short circuit evaluation in ppl?

Short-Circuit Evaluation: Short-circuiting is a programming concept in which the compiler skips the execution or evaluation of some sub-expressions in a logical expression. The compiler stops evaluating the further sub-expressions as soon as the value of the expression is determined.

What is the use of short circuit operator?

In Java logical operators, if the evaluation of a logical expression exits in between before complete evaluation, then it is known as Short-circuit. A short circuit happens because the result is clear even before the complete evaluation of the expression, and the result is returned.


2 Answers

Closest thing I can find to an 'official' mention of PHP's short-circuit implementation: http://php.net/manual/en/language.operators.logical.php

like image 161
Mike B Avatar answered Nov 04 '22 16:11

Mike B


This is not an uncommon feature of expression evaluation. The PHP manual page on logical operators makes a passing reference to it in one of the illustrative examples though.

Short circuit evaluation is a commonly exploited idiom, and you can rely on its continued support in the language, otherwise vast amounts of code would break!

like image 1
Paul Dixon Avatar answered Nov 04 '22 17:11

Paul Dixon