php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46906 array_unshift() changes first key
Submitted: 2008-12-19 10:12 UTC Modified: 2008-12-20 16:53 UTC
From: malte dot hamburg at gmx dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.5 OS: WinXP
Private report: No CVE-ID: None
 [2008-12-19 10:12 UTC] malte dot hamburg at gmx dot de
Description:
------------
After using "array_unshift" (and the first key is numeric) the first (old) key of the array has  changed.

We use PHP 5.2.5 (API 20041225)


Reproduce code:
---------------
$test = array("4711" => "4711", "Hello" => "Hello");
print_r($test);
array_unshift($test, array(null => "New text"));
print_r($test);

Expected result:
----------------
Array ( [4711] => 4711 [Hello] => Hello ) 
Array ( [0] => Array ( [] => New text ) [1] => 4711 [Hello] => Hello ) 

Actual result:
--------------
Array ( [4711] => 4711 [Hello] => Hello ) 
Array ( [0] => Array ( [] => New text ) [4711] => 4711 [Hello] => Hello ) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-20 16:53 UTC] jani@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

Works fine in 5.2.8.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 00:01:30 2024 UTC