php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28031 Results of comparison differ by Windows and unix.
Submitted: 2004-04-16 20:05 UTC Modified: 2004-04-26 00:26 UTC
From: yiwakiri at st dot rim dot or dot jp Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.6, 4.3.7-dev OS: Windows 2k, XP, 98
Private report: No CVE-ID: None
 [2004-04-16 20:05 UTC] yiwakiri at st dot rim dot or dot jp
Description:
------------
The results of comparison differ by Windows and unix.

Windows:
c:\> php -r "var_dump(('0d1' == '0d2'));"
bool(true)

Unix like OS:
% php -r "var_dump(('0d1' == '0d2'));"
bool(false)

I expect the same behavior for both.


Reproduce code:
---------------
c:\> php -r "var_dump(('0d1' == '0d2'));"

Expected result:
----------------
bool(false)

Actual result:
--------------
bool(true)

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-17 15:24 UTC] postings-php-bug at hans-spath dot de
[Windows XP Pro SP1]

D:\PHP>4.3.2\php-cli -r "var_dump(('0d1' == '0d2'));"
bool(true)
D:\PHP>4.3.3\php-cli -r "var_dump(('0d1' == '0d2'));"
bool(true)
D:\PHP>4.3.4\php-cli -r "var_dump(('0d1' == '0d2'));"
bool(true)
D:\PHP>4.3.6\php-cli -r "var_dump(('0d1' == '0d2'));"
bool(true)

D:\PHP>php4-win32-STABLE-latest\php-cli -r "var_dump(('0d1' == '0d2'));"
bool(true)
D:\PHP>php4-win32-STABLE-latest\php-cli -v
PHP 4.3.7-dev (cli) (built: Apr 17 2004 14:18:37)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies


[Linux 2.6.5]

hs@test:~/compile/php-4.3.6% sapi/cli/php -r "var_dump(('0d1' == '0d2'));"
bool(false)
 [2004-04-19 02:24 UTC] yiwakiri at st dot rim dot or dot jp
A snapshot is also the same behavior.

C:\>php -v
PHP 4.3.7-dev (cli) (built: Apr 17 2004 10:21:09)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

C:\>php -r "var_dump(('0d1' == '0d2'));"
bool(true)
 [2004-04-19 10:34 UTC] yiwakiri at st dot rim dot or dot jp
Hmm, I'm confused.

Windows(2k, XP 98):
C:\>php -r "var_dump('0d1' == '0d2');"     (1)
bool(true)
C:\>php -r "var_dump('00d1' == '00d2');"   (2)
bool(false)
C:\>php -r "var_dump('0a1' == '0a2');"     (3)
bool(false)

Unix like OS:
% php -r "var_dump('0d1' == '0d2');"       (4)
bool(false)
% php -r "var_dump('0a1' == '0a2');"       (5)
bool(false)

Only (1) does not bring a result to expect.
 [2004-04-19 15:11 UTC] postings-php-bug at hans-spath dot de
D:\PHP>ver
Microsoft Windows XP [Version 5.1.2600]

D:\PHP>lastest\php-cli -v
PHP 4.3.7-dev (cli) (built: Apr 19 2004 14:16:52)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

D:\PHP>5.0.0RC1\php -v
PHP 5.0.0RC1 (cli) (built: Mar 18 2004 18:20:03)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.0RC1, Copyright (c) 1998-2004 Zend Technologies

D:\PHP>lastest\php-cli test\string_comparison.php 0x1 0x2
( '0x1' == '0x2' ) = bool(false)
D:\PHP>lastest\php-cli test\string_comparison.php 0d1 0d2
( '0d1' == '0d2' ) = bool(true)
D:\PHP>lastest\php-cli test\string_comparison.php 0d1x 0d2x
( '0d1x' == '0d2x' ) = bool(false)
D:\PHP>lastest\php-cli test\string_comparison.php 0d1 0dx1
( '0d1' == '0dx1' ) = bool(false)
D:\PHP>lastest\php-cli test\string_comparison.php 0d1 0xd1
( '0d1' == '0xd1' ) = bool(true)
D:\PHP>lastest\php-cli test\string_comparison.php 0d1 0xd2
( '0d1' == '0xd2' ) = bool(true)
D:\PHP>lastest\php-cli test\string_comparison.php d1 xd2
( 'd1' == 'xd2' ) = bool(false)
D:\PHP>lastest\php-cli test\string_comparison.php d1 xd1
( 'd1' == 'xd1' ) = bool(false)
D:\PHP>lastest\php-cli test\string_comparison.php 0e9 0xe4
( '0e9' == '0xe4' ) = bool(true)

D:\PHP>5.0.0RC1\php test\string_comparison.php 0e9 0xe4
( '0e9' == '0xe4' ) = bool(true)

I wonder why this hasn't been discovered before. All my currently installed (win32) versions (4.3.[2346], 5.0.0RC1) suffer from this problem.
 [2004-04-19 15:31 UTC] wez@php.net
Most likely due to strtol() implementation in the M$ libc.
Try using the === operator or strcmp() instead.

(strings that look like numbers might be compared as numbers using the == operator)


 [2004-04-20 01:26 UTC] yiwakiri at st dot rim dot or dot jp
Hi, wez

Why does it deceive as a problem of strtol()?
Although it is comparison of STRING and STRING,
Is it a problem if strtol() is called?
In Unix Like OS, it is not thought that strtol() is called.
 [2004-04-22 06:52 UTC] yiwakiri at st dot rim dot or dot jp
Thanks Wez
I understood the difference in the action of strtol().

It checked that read a program and strtol() was called
via is_numeric_string() also by unix.
However, it is troubled with an understanding whether is_numeric_string() is called in zendi_smart_strcmp() for that it turns out that it is comparison of STRING and STRING in advance.
I want to know the reason for not calling zend_binary_zval_strcmp() directly to which can be convinced.

Thanks Wez
I understood the difference in the action of strtol().
 [2004-04-26 00:26 UTC] sniper@php.net
We still can not change the Windows, wait for them to release the source and we'll fix it. :)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Aug 14 08:01:27 2024 UTC