php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #68542 Relational operators semantics is different with actual behavior.
Submitted: 2014-12-03 14:02 UTC Modified: -
From: y dot uchiyama dot 1015 at gmail dot com Assigned:
Status: Closed Package: PHP Language Specification
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2014-12-03 14:02 UTC] y dot uchiyama dot 1015 at gmail dot com
Description:
------------
The semantics of relational operators (in 10-expressions.md) is different with the actual behavior of PHP, in case that both operands are string (the semantics says rules 2 and 4 are applied).

In this case, numeric comparison is applied only if both operands are numeric string without overflow, otherwise lexical comparison is applied.

Some examples are shown below.
echo ('1' == '0x1') . "\n"; // true
echo ('1' == '1a') . "\n"; // false
echo ('1234567890' == '1234567890.0') . "\n"; // true
echo ('123456789012345678901234567890' == '123456789012345678901234567890.0') . "\n"; // false
echo ('1e10' == '1.0e10') . "\n"; // true
echo ('1e1000' == '1.0e1000') . "\n"; // false


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-28 22:47 UTC] stas@php.net
Automatic comment on behalf of smalyshev@gmail.com
Revision: http://git.php.net/?p=php-langspec.git;a=commit;h=976a43c717d81cba08b81d5cfa2ed569979d0e2b
Log: Fixed bug #68542
 [2015-06-28 22:47 UTC] stas@php.net
-Status: Open +Status: Closed
 [2015-06-28 23:20 UTC] stas@php.net
Automatic comment on behalf of smalyshev@gmail.com
Revision: http://git.php.net/?p=php-langspec.git;a=commit;h=976a43c717d81cba08b81d5cfa2ed569979d0e2b
Log: Fixed bug #68542
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 01:01:28 2024 UTC