#30768 [NEW]: array_unshift does not honor key types

From: Date: Fri, 12 Nov 2004 13:15:41 +0000
Subject: #30768 [NEW]: array_unshift does not honor key types
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-68985@lists.php.net to get a copy of this message
From: olito24 at gmx dot de Operating system: debian linux 2.4.21-1-686 PHP version: 4.3.9 PHP Bug Type: Arrays related Bug description: array_unshift does not honor key types Description: ------------ the array that is to be passed to array_unshift() has strings as its keys. if a key is a number, array_unshift does not keep the type string for this key in the resulting array. in the following example, the top level key [1] should in fact be [181050] (as a string). it is index [1] because the first entry is [0], which in fact is meant to be an integer value. an example how i used unshift to insert the first entry in the already existing array: array_unshift ($relativeCampaignData_A, array ('id' => 0, 'title' => 'k.A.')); (usually the [id] entries are strings, the first top array element is an exception. the resulting array is: Array ( [0] => Array ( [id] => 0 [title] => k.A. ) [e94a5a] => Array ( [id] => e94a5a [title] => example1 ) [0f298f] => Array ( [id] => 0f298f [title] => example2 ) [1] => Array ( [id] => 181050 [title] => thisKeyIsTheError ) [1cfb8b] => Array ( [id] => 1cfb8b [title] => example3 ) ) before using unshift index [1] was associative index [181050] as a string by using strval. Reproduce code: --------------- $array = array('123abc' => array('id' = '123abc', 'title' = 'example2'), '456789' => array('id' = '456789', 'title' = 'errorexample')); print_r ($array); echo '<br><br>'; array_unshift ($array, array('id' => 0, 'title' => 'example1')); print_r ($array); Expected result: ---------------- $array [0] = array $array ['123abc'] = array $array ['456789'] = array Actual result: -------------- $array [0] = array $array ['123abc'] = array $array [1] = array -- Edit bug report at http://bugs.php.net/?id=30768&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30768&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30768&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30768&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30768&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30768&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30768&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30768&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30768&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30768&r=support Expected behavior: http://bugs.php.net/fix.php?id=30768&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30768&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30768&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30768&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30768&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30768&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30768&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30768&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30768&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30768&r=mysqlcfg

« previous php.bugs (#68985) next »