php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55373 Unexpected behavior involving conditions.
Submitted: 2011-08-06 01:44 UTC Modified: 2011-08-06 02:25 UTC
From: computerboy0 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: OS X 10.5.8 (Irrelevant)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: computerboy0 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-08-06 01:44 UTC] computerboy0 at gmail dot com
Description:
------------
Using IF or WHILE statements (possibly others?), the code below produces 
unexpected results.

Test script:
---------------

//Set a variable with an initial value.
$TEST="Initial";

//Set the variable to a different value, then test for it.
if($TEST="Secondary" && $TEST==="Secondary") echo "Expected result occurred.";

else echo "Expectation FAIL";

//During the ($TEST==="Secondary") condition, $TEST should match "Secondary", having just been set to "Secondary".  Instead, there $TEST is actually still "Initial".

echo "\n".$TEST;

Expected result:
----------------
$TEST should be set to "Secondary" within the IF statement and then reflect that 
within said IF statement. It does not seem to.

Script result:

Expected result occurred.
Secondary

Actual result:
--------------
What actually happens is that $TEST only becomes "Secondart" *after* the entire IF 
statement has processed.  So any following comparison with $TEST still yields its 
initial value.

Script result:

Expectation FAIL
Secondary

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-06 02:25 UTC] arpad@php.net
-Status: Open +Status: Bogus
 [2011-08-06 02:25 UTC] arpad@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Please see http://www.php.net/manual/en/language.operators.precedence.php

&& has a higher precedence than = so the result of that expression is correctly false.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Sep 11 01:00:01 2025 UTC