From:             
Operating system: Ubuntu 10.10
PHP version:      5.3SVN-2011-03-17 (SVN)
Package:          Arrays related
Bug Type:         Bug
Bug description:array_unshift and multidimension arrays bug

Description:
------------
When using array_unshift() on multidimension arrays there is a bug when
index in array does not exists. When you have array with arrays inside like
this:



$arr = array(

        array('ddddd'),

        array('eeee'),

        array('ffff'),

        array('gggg'),

);



and you use:



array_unshift($arr[4], 4);



this function not only show you warning message, but also add one element
with null value to the end (!) of $arr array. It should not be working like
that. It should show a warning and do nothing.



My version of PHP:

piotrekkr@piotrekkr-desktop:/var/www$ php -v

PHP 5.3.3-1ubuntu9.3 with Suhosin-Patch (cli) (built: Jan 12 2011 16:07:38)


Copyright (c) 1997-2009 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies



OS: Ubuntu 10.10

Test script:
---------------
<?php

$arr = array(

        array('ddddd'),

        array('eeee'),

        array('ffff'),

        array('gggg'),

);

array_unshift($arr[4], 4);

print_r($arr);

Expected result:
----------------
PHP Warning:  array_unshift() expects parameter 1 to be array, null given
in /var/www/unshift_test.php on line 9

Array

(

    [0] => Array

        (

            [0] => ddddd

        )



    [1] => Array

        (

            [0] => eeee

        )



    [2] => Array

        (

            [0] => ffff

        )



    [3] => Array

        (

            [0] => gggg

        )

)



Actual result:
--------------
PHP Warning:  array_unshift() expects parameter 1 to be array, null given
in /var/www/unshift_test.php on line 9

Array

(

    [0] => Array

        (

            [0] => ddddd

        )



    [1] => Array

        (

            [0] => eeee

        )



    [2] => Array

        (

            [0] => ffff

        )



    [3] => Array

        (

            [0] => gggg

        )



    [4] => 

)



-- 
Edit bug report at http://bugs.php.net/bug.php?id=54288&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54288&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54288&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54288&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54288&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54288&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54288&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54288&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54288&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54288&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54288&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54288&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54288&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54288&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54288&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54288&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54288&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54288&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54288&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54288&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54288&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54288&r=mysqlcfg

Reply via email to