php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74550 Illegal behaviour in booleans
Submitted: 2017-05-06 13:11 UTC Modified: 2017-05-06 13:17 UTC
From: lee dot traynor at skeptic dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.18 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: lee dot traynor at skeptic dot de
New email:
PHP Version: OS:

 

 [2017-05-06 13:11 UTC] lee dot traynor at skeptic dot de
Description:
------------
---
From manual page: http://www.php.net/language.types.boolean
---
Evaluation of boolean expressions leads to conflicting (and incorrect) results.

Test script:
---------------
$ctm = true and (false or false);
var_dump ($ctm, true and (false or false));

returns true, false

Expected result:
----------------
Should return false, false, and does in fact return this if the expression that is assigned to $ctm is enclosed in brackets.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-06 13:17 UTC] nikic@php.net
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: Scripting Engine problem
 [2017-05-06 13:17 UTC] nikic@php.net
"and" has lower precedence than "=", so this expression is interpreted as ($ctm = true) and (false or false). See http://php.net/manual/en/language.operators.precedence.php for the operator precedence table.

You are looking for && and ||.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 20 01:00:01 2025 UTC