ID:               38679
 Updated by:       [EMAIL PROTECTED]
 Reported By:      php at rebel dot com dot au
-Status:           Assigned
+Status:           Closed
 Bug Type:         Documentation problem
 Operating System: any
 PHP Version:      4.4.4
 Assigned To:      sean
 New Comment:

This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.

The manual already stated that ternary expressions are evaluated
left-to-right. However, I agree: this behaviour is confusing. I added a
note that will help clear this up.

S



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

[2006-09-01 13:12:51] php at rebel dot com dot au

Reclassifying this bug report as a document problem is somewhat akin to
sweeping the dirt under the carpet.

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

[2006-09-01 11:37:01] [EMAIL PROTECTED]

Reclassified as documentation problem.

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

[2006-09-01 11:24:41] php at rebel dot com dot au

Description:
------------
As has been reported many times the ternary operator ?: does not
operate in a logical fashion.

I have seen this bug reported and returned as bogus. how can that be.

the construct "expr1 ? expr2:expr3 ? expr4:expr5" should be
semantically similar to

if (expr1)
   expr2
else 
  if (expr3)
     expr4
  else
     expr5


Just because many people may rely on the incorrect operation of this
operator does not mean it should not be fixed.
(How can anyone rely on that weird bit of work, see test result below)
And fixing it wouldnt break code that uses parenthesis to correct this
bug.

I know no one likes to admit they got it wrong but this is a
particularly bad faux pas and should be corrected to bring this
operator into line with what would be considered the norm.

No other language I know that has this construct evaluates it in the
way PHP does.

even the documentation seems clear on how it should operate

"The expression (expr1) ? (expr2) : (expr3)  evaluates to expr2 if
expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE."
http://www.php.net/manual/en/language.operators.comparison.php

There is nothing in that line of explanation that says if expr3 is not
bracketed it will be evaluated TO THE EXCLUSION of expr1 which is
obviously whats happening (see test results below)

If there is a valid reason for the way this operator is evaluated
please then explain so that I can pass on this perl of wisdom.


Reproduce code:
---------------
$true1 = false;
$true2 = false;

echo( $true1 ? 'true1':$true2 ? 'true2':'false' );

$true1 = true;
$true2 = false;

echo( $true1 ? 'true1':$true2 ? 'true2':'false' );

$true1 = false;
$true2 = true;

echo( $true1 ? 'true1':$true2 ? 'true2':'false' );

$true1 = true;
$true2 = true;

echo( $true1 ? 'true1':$true2 ? 'true2':'false' );


Expected result:
----------------
false
true1
true2
true1

Actual result:
--------------
false
true2
true2
true2


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


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

Reply via email to