php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21782 array key comparision issue(?)
Submitted: 2003-01-20 15:44 UTC Modified: 2003-01-20 19:13 UTC
From: carlos at wfmh dot org dot pl Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.3 OS: Linux GNU/Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: carlos at wfmh dot org dot pl
New email:
PHP Version: OS:

 

 [2003-01-20 15:44 UTC] carlos at wfmh dot org dot pl
test.php:
<?php
  $val1 = "any";
  $test = array("any"=>"any", "3"=>"+3", "2"=>"+2",
                "1"=>"+1", "0"=>"0", "-1"=>"-1",
                "-2"=>"-2", "-3"=>"-3" );
  foreach( $test AS $key=>$val )
     printf("'%s' vs. '%s' result: %d\n", $val1, $key, ($key == $val1) );
?>

$ php test.php
'any' vs. 'any' result: 1
'any' vs. '3' result: 0
'any' vs. '2' result: 0
'any' vs. '1' result: 0
'any' vs. '0' result: 1
'any' vs. '-1' result: 0
'any' vs. '-2' result: 0
'any' vs. '-3' result: 0

$ php -v
4.2.3

Shouldn't "'any' vs. '0'" give 0 as result?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-20 19:13 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

0 == 0 hence $key == $val1 is true. Not a bug.
 [2003-01-21 02:32 UTC] carlos at wfmh dot org dot pl
However I expected this behaviour to be numeric index related, I still consider it a bug. Mostly becasue I compared "any" (which ain't "0") with "0", and the result should be false, as these two are not equal. It does not matter that "any" is the 1st element in the array (hence the 'internal' index 0 is used). I gave an "any" index to this element, so I can't quite understand why it's ok to that PHP evaluates different condition than programmer wrote.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC