ID:          41228
 Updated by:  [EMAIL PROTECTED]
 Reported By: terminatorul at gmail dot com
 Status:      Open
 Bug Type:    Documentation problem
 PHP Version: Irrelevant
 New Comment:

My point was that the term "short-circuit" is already mentioned twice
on the page, if you didn't know what it meant in this context then a
google search for "short-circuit operator" would yield a page full of
relevant results.

Of course it could be spelled out in the text, but even if I was in
favour of doing so, I don't have phpdoc karma. That's why I just stated
my opinion and left the bug open.


Previous Comments:
------------------------------------------------------------------------

[2007-04-30 11:50:08] terminatorul at gmail dot com

My point exactly.

A programing language may or may not guarantee side-effects from
evaluation of operands to logical operators. Or at least would say
that it is undefined if the side-effect occurs.

The proffesional C++ programmer will find it normal for the language to
shortcut the expression, while a beginner will not understand what's
wrong with his/her code.

------------------------------------------------------------------------

[2007-04-30 11:44:35] [EMAIL PROTECTED]

Good ole MS! http://support.microsoft.com/kb/817250


------------------------------------------------------------------------

[2007-04-30 11:42:27] [EMAIL PROTECTED]

Two opposing thoughts.

Delphi -
http://info.borland.com/techpubs/delphi/delphi5/oplg/syntlmnt.html#10548
In Delphi, shortcut/short-circuit is optional, though as standard it is
enabled.

VB -
http://www.informit.com/guides/content.asp?g=dotnet&seqNum=480&rl=1
Seemingly VB does NOT have a short circuit.

Who do you believe. For the seasoned programmer, this is perfectly
obvious. But if you're upgrading your skill set from, say, VB, then this
REALLY odd behaviour is completely new. And what debugging would you
provide?

This should be documented and probably in several places as there are
many references to boolean logic throughout the manual.

It is the LACK of documentation on this standard feature within PHP
that is the issue.

------------------------------------------------------------------------

[2007-04-30 10:08:31] [EMAIL PROTECTED]

This isn't a side-effect, but an intrinsic property of these operators.
As two out of the four user notes on the page mention, the first dating
back to 1999, these operators short-circuit.

Perhaps this could be explained in the text to make it clearer for
people new to programming, but I don't think there's any great need;
I assume most people can look up terms they're not familiar with.

------------------------------------------------------------------------

[2007-04-30 09:00:14] [EMAIL PROTECTED]

Agreed.

<?php
// Echo's F and does NOT set $a.
echo (False && ($a=1)) ? 'T' : 'F';

// Echo's T, sets $b but does not set $c.
echo (($b=2) || False || ($c=3)) ? 'T':'F';

// Turn off notices about undefined variables for $a and $c.
error_reporting(E_ALL & ~E_NOTICE);

// Rather than "1 2 3", we get just " 2 ".
echo "$a $b $c";
?>

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/41228

-- 
Edit this bug report at http://bugs.php.net/?id=41228&edit=1

Reply via email to