php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1974 Comparison of strings "2.2" and "2.20" returns TRUE
Submitted: 1999-08-05 12:40 UTC Modified: 1999-08-05 14:48 UTC
From: stewart-a at moving-picture dot co dot uk Assigned:
Status: Closed Package: Other
PHP Version: 3.0.11 OS: Linux 2.2.5-15
Private report: No CVE-ID: None
 [1999-08-05 12:40 UTC] stewart-a at moving-picture dot co dot uk
Strings seems to get converted to double for "==" comparison.

<?
$a = (string) 2.2;
$b = (string) 2.20;
if ( "$a" == "$b" ) {
        echo "The string $a equals string $b";
} else {
        echo "The string $a does not equal string $b";
}
?>

Clearly the "strings" 2.2 and 2.20 should not be equivalent.

If this isn't considered a bug then how does one compare two strings like this. I've tried :
if (strval($a) == strval($b) 

but the only successful workaround I've found is:
if ( "$a" == "$b" && strlen($a) == strlen($b) ) {

PHP Modules:
./configure  --with-mysql=/usr/local/mysql --with-apache=/usr/local/src/apache_1.3.6 --enable-track-vars

Configuration

                                                    php3.ini file path is set to: /usr/local/lib
                                          Directive
                                                              Master Value
                                                                                    Local Value
                                  arg_separator
                                                          &
                                                                               &
                                  asp_tags
                                                         0
                                                                              0
                                  auto_prepend_file
                                                          none
                                                                               none
                                  auto_append_file
                                                          none
                                                                               none
                                  browscap
                                                          none
                                                                               none
                                  cgi_ext
                                                          none
                                                                               none
                                  debugger.host
                                                          none
                                                                               none
                                  debugger.port
                                                         0
                                                                              0
                                  define_syslog_variables
                                                         0
                                                                              0
                                  display_errors
                                                         1
                                                                              1
                                  doc_root
                                                          none
                                                                               none
                                  enable_dl
                                                         1
                                                                              1
                                  engine
                                                         1
                                                                              1
                                  error_log
                                                          none
                                                                               none
                                  error_append_string
                                                          none
                                                                               none
                                  error_prepend_string
                                                          none
                                                                               none
                                  error_reporting
                                                         55
                                                                              55
                                  extension_dir
                                                          none
                                                                               none
                                  gpc_order
                                                          GPC
                                                                               GPC
                                  ignore_user_abort
                                                         0
                                                                              0
                                  include_path
                                                          none
                                                                               none
                                  isapi_ext
                                                          none
                                                                               none
                                  last_modified
                                                         0
                                                                              0
                                  log_errors
                                                         0
                                                                              0
                                  max execution time
                                                         30
                                                                              30
                                  magic_quotes_gpc
                                                         0
                                                                              0
                                  magic_quotes_runtime
                                                         0
                                                                              0
                                  magic_quotes_sybase
                                                         0
                                                                              0
                                  memory limit
                                                         8388608
                                                                              8388608
                                  nsapi_ext
                                                          none
                                                                               none
                                  open_basedir
                                                          none
                                                                               none
                                  precision
                                                         14
                                                                              14
                                  safe_mode
                                                         0
                                                                              0
                                  safe_mode_exec_dir
                                                          /usr/local/php/bin
                                                                               /usr/local/php/bin
                                  sendmail_from
                                                          none
                                                                               none
                                  sendmail_path
                                                          /usr/sbin/sendmail -t
                                                                               /usr/sbin/sendmail -t
                                  short_open_tag
                                                         1
                                                                              1
                                  smtp
                                                          localhost
                                                                               localhost
                                  sql_safe_mode
                                                         0
                                                                              0
                                  track_errors
                                                         0
                                                                              0
                                  track_vars
                                                         1
                                                                              1
                                  upload_max_filesize
                                                         2097152
                                                                              2097152
                                  upload_tmp_dir
                                                          none
                                                                               none
                                  user_dir
                                                          none
                                                                               none
                                  warn_plus_overloading
                                                         0
                                                                              0
                                  xbithack
                                                         0
                                                                              0
                                  browscap
                                                          none
                                                                               none
                                  y2k_compliance
                                                         0
                                                                              0
                                  highlight_comment
                                                          #FF8000
                                                                               #FF8000
                                  highlight_default
                                                          #0000BB
                                                                               #0000BB
                                  highlight_html
                                                          #000000
                                                                               #000000
                                  highlight_string
                                                          #DD0000
                                                                               #DD0000
                                  highlight_bg
                                                          #FFFFFF
                                                                               #FFFFFF
                                  highlight_keyword
                                                          #007700
                                                                               #007700




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-08-05 14:48 UTC] rasmus at cvs dot php dot net
strcmp() just like C
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC