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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 20:01:30 2024 UTC