Bug #71099 [Opn->Nab]: Basic assertion failing in PHP 7
| From: | nikic@php.net | Date: | Fri, 11 Dec 2015 23:51:25 +0000 |
| Subject: | Bug #71099 [Opn->Nab]: Basic assertion failing in PHP 7 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197816@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71099&edit=1
ID: 71099
Updated by: nikic@php.net
Reported by: cdtreeks at gmail dot com
Summary: Basic assertion failing in PHP 7
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: CentOS 7
PHP Version: 7.0.0
Block user comment: N
Private report: N
New Comment:
This is how PHP has always worked, nothing to do with PHP 7.
The "logic" behind it is that an integer to string comparison will cast the string to an
integer, thus giving you the result you observe. I think this is generally agreed to be not very
useful, but also unlikely to change due to BC concerns.
Previous Comments:
------------------------------------------------------------------------
[2015-12-11 23:42:48] cdtreeks at gmail dot com
Description:
------------
Comparing two different values is failing to assert correctly in the latest release of PHP 7. See
'Test script' below for more details.
Test script:
---------------
<?php
$val_1 = 'test_string'; // Value is 'test_string'
$val_2 = (int) $val_1; // Value is 0
if ($val_1 == $val_2) {
// PHP believes 'test_string' == 0
...
} else {
...
}
Expected result:
----------------
The else clause should be hit.
Actual result:
--------------
The initial condition is returning true
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71099&edit=1