W
W
WoZ2012-03-07 22:28:21
PHP
WoZ, 2012-03-07 22:28:21

PHP and strings close to maxint?

Experts are invited to "think about it")
Found a strange behavior of such code.

$id1 = '9223372036854775888';<br/>
$id2 = '9223372036854775899';<br/>
var_dump($id1 == $id2);<br/>

The result is true. The mana says that numeric strings are compared as integers. What should be guided by to come up with this? Those. when the form of the compared strings is not known in advance, then you can get anything at the output.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Max, 2012-03-07
@7workers

Make a small post in the feed, everyone should know this. The “bug” has been hanging since 2007, so it is unlikely that anything will change: bugs.php.net/bug.php?id=43304

P
pompeev, 2012-03-07
@pompeev

Dangerous thing, I also have true ==, === falls.
when specifying the type (string) even true

M
Meliborn, 2012-03-07
@Meliborn

use ===, Luke

V
Vladimir Chernyshev, 2012-03-07
@VolCh

Чем нужно руководствоваться чтобы такое придумать?
The fact that PHP is originally a template engine works with text data (script input from a web server, entries in the database, files are all strings), but the data is often numeric in nature. So they "facilitated" the life of the developers, so that it was not necessary to bring types for every sneeze.
I remember accidentally stumbled upon this dubious "feature", compared something like this: $str1. 'fake' == $str2. 'fake'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question