From: tater at potatoe dot com
Operating system: OS X 10.2
PHP version: 5CVS-2003-07-14 (dev)
PHP Bug Type: Arrays related
Bug description: array keys that are strings but numeric behave incorrectly
Description:
------------
This is really bug #23935, but that's marked 'Closed' and I am still
seeing the problem in the current PHP5 code. It's beyond array_flip(),
too, strictly. I first saw this in $_POST with a field named "myfield[1]"
- this comes through as $_POST["myfield"]["1"]. Same with array_combine()
using array("1") as the key array.
Reproduce code:
---------------
submit a form with hidden field named 'myfield[1]':
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="myfield[1]" value="1" >
<input type="submit">
</form>
<?php
function testit($a)
{
static $tick = 1;
echo "<li>test ", $tick++, ":\n";
var_dump($a, array_key_exists(key($a), $a), empty($a[1]),
empty($a['1']));
}
testit(array("1"=>"1"));
testit(array_flip(array(1=>"1")));
testit(array_combine(array('1'),array('1')));
if (!empty($_POST['myfield'])) { testit($_POST['myfield']); }
?>
Expected result:
----------------
Output for test 2 on PHP 4.3.3RC1 (cli) (built: Jun 20 2003 23:09:34)
(DEBUG):
array(1) {
[1]=>
int(1)
}
bool(true)
bool(false)
bool(false)
Actual result:
--------------
Output for test 2 on PHP 5.0.0b2-dev (cli) (built: Jul 14 2003 14:14:54)
(DEBUG):
array(1) {
["1"]=>
int(1)
}
bool(false)
bool(true)
bool(true)
--
Edit bug report at http://bugs.php.net/?id=24652&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=24652&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=24652&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=24652&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=24652&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=24652&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=24652&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=24652&r=support
Expected behavior: http://bugs.php.net/fix.php?id=24652&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=24652&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=24652&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=24652&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24652&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=24652&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=24652&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=24652&r=gnused