|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-14 16:53 UTC] tater at potatoe dot com
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) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
The OS is irrelevant. This simple script shows that there indeed is a bug: <?php /* This works */ $f = array('7' => 0); var_dump($f); var_dump(array_key_exists(7, $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)); var_dump(array_key_exists('7', $f)); ?> Result with PHP 4.3.3RC2-dev: ----------------------------- array(1) { [7]=> int(0) } bool(true) bool(true) array(1) { [7]=> int(0) } bool(true) bool(true) Result with PHP 5.0.0b2-dev: --------------------- array(1) { [7]=> int(0) } bool(true) bool(true) array(1) { ["7"]=> int(0) } bool(false) bool(false) Assigning to Sterling who broke it. :)