php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71706 Assignment operators in "if" expression
Submitted: 2016-03-03 07:20 UTC Modified: 2016-03-03 10:10 UTC
From: dmitryscaletta at mail dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.3 OS: Windows 10
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: dmitryscaletta at mail dot ru
New email:
PHP Version: OS:

 

 [2016-03-03 07:20 UTC] dmitryscaletta at mail dot ru
Description:
------------
I expect "78" or warning, but i have "1"

Test script:
---------------
<?php
if ($var = 78 || $var = 456 || $var = 464) {
    echo $var;
}

Expected result:
----------------
1

Actual result:
--------------
78

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-03 07:21 UTC] dmitryscaletta at mail dot ru
(I made a mistake)
Expected result:
----------------
78

Actual result:
--------------
1
 [2016-03-03 07:28 UTC] dmitryscaletta at mail dot ru
-Status: Open +Status: Closed
 [2016-03-03 07:28 UTC] dmitryscaletta at mail dot ru
I realized my mistake. || returns bool
 [2016-03-03 07:30 UTC] inefedor at gmail dot com
Operator || has higher precedence than assignment operator hence your expression is being treated as $var = (78 || $var = (456 || $var = 464))
 [2016-03-03 10:10 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC