php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23935 array_key_exists no longer juggles types correctly
Submitted: 2003-05-31 23:12 UTC Modified: 2003-06-30 13:51 UTC
From: dave at codewhore dot org Assigned: sterling (profile)
Status: Closed Package: Arrays related
PHP Version: 5CVS-2003-05-31 (dev) OS: Linux 2.4
Private report: No CVE-ID: None
 [2003-05-31 23:12 UTC] dave at codewhore dot org
Hi:

The following script produces different output with PHP 5 HEAD than it does with the PHP 4.3 stable branch:

<?php
  $f[1] = 1;
  var_dump(array_key_exists('1', $f));
?>

With PHP 4.3 stable, I get:
  bool(true)

With PHP 5 HEAD, I get:
  bool(false)

It appears that PHP 5 HEAD is missing the call to HANDLE_NUMERIC() in zend_hash_exists (Zend/zend_hash.c). The ZE2 changelog shows that it was moved:

  move HANDLE_NUMERIC() from the hash table
  implementation upstream to the places that
  actually need to use it.

But I'm unable to figure out where the equivalent functionality was added back. Am I missing something?

Thanks in advance,

- Dave

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-05 11:16 UTC] sterling@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

fixed in cvs, thanks.
 [2003-06-06 16:07 UTC] dave at codewhore dot org
Hi Sterling:

I think there's a remaining (related) problem, this time with array keys that are strings. I've enclosed a test case.

<?php
  /* This works */
  $f = array('7' => 0);
  var_dump($f);
  var_dump(array_key_exists(7, $f));

  /* This doesn't */
  $f = array_flip(array('7'));
  var_dump($f);
  var_dump(array_key_exists(7, $f));
?>

On PHP 5, I get:

array(1) {
  [7]=>
  int(0)
}
bool(true)
array(1) {
  ["7"]=>
  int(0)
}
bool(false)

On PHP 4 I get:
array(1) {
  [7]=>
  int(0)
}
bool(true)
array(1) {
  [7]=>
  int(0)
}
bool(true)


Thanks in advance,
- Dave
 [2003-06-30 13:51 UTC] sterling@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-07-14 16:19 UTC] tater at potatoe dot com
I am still seeing this on the latest CVS code. It goes beyond array_flip(), too. I first saw this in an array value from $_REQUEST, and array_combine() will produce the same effect - anything that can get a numeric array key to be a string rather than a number.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 05:01:30 2024 UTC