From:             cfoster at frozenheads dot com
Operating system: OS X 10.3.6
PHP version:      5.0.2
PHP Bug Type:     Feature/Change Request
Bug description:  array_merge no longer type checks as it did in php4

Description:
------------
In PHP4 one could call array_merge with non-array or unset variables and
it would still correctly merge any arrays that were passed (i.e.,
type-checking was done within the function). I tested this in 4.3.8 for
BSD.

In PHP5 if any of the parameters are not arrays, the function returns
null.  I tested with 5.0.2 Mac OS X entropy release 1. 
   http://www.entropy.ch/software/macosx/php/

It was very handy to be able to pass a bunch of variables and get back the
merged result of all the arrays without having to check each one to make
sure it was set.

As is, instead of one line:

   $ar_merged = array_merge( $ar1, $ar2, $ar3, $ar4 );

one would have to have a long if-block:

$ar_merged = array();
if( is_array( $ar1 ) )
    $ar_merged = array_merge( $ar_merged, $ar1 );
if( is_array( $ar_2 ) )
    ...


Reproduce code:
---------------
<?php
$ar1 = array( "one", "two" );
$ar2 = "three";   // Optionally: comment out this line.

$ar_merged = array_merge( $ar1, $ar2 );
        
if( isset( $ar_merged ) )
    print_r( $ar_merged );
else
    print "Blarmy! Unset array!";
?>

Expected result:
----------------
In 4.3.8 it returned:

Array
(
    [0] => one
    [1] => two
    [2] => three
)

but I think it should still at least use the variables that are arrays:

Array
(
    [0] => one
    [1] => two
)

Also, if $ar2 is not defined at all it should return:

Array
(
    [0] => one
    [1] => two
)


Actual result:
--------------
Blarmy! Unset array!

It's ignoring ALL passed variables if ANY of them are not arrays, and
returning a null result.


-- 
Edit bug report at http://bugs.php.net/?id=30737&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30737&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=30737&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=30737&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30737&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30737&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30737&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30737&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30737&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30737&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30737&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=30737&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=30737&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30737&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30737&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30737&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30737&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30737&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30737&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30737&r=mysqlcfg

Reply via email to