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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 - 20 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Tue Mar 19 06:01:30 2024 UTC