#30737 [Opn->Bgs]: array_merge no longer type checks as it did in php4
| From: | derick@php.net | Date: | Tue, 09 Nov 2004 22:50:42 +0000 |
| Subject: | #30737 [Opn->Bgs]: array_merge no longer type checks as it did in php4 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-68867@lists.php.net to get a copy of this message | ||
ID: 30737
Updated by: derick@php.net
Reported By: cfoster at frozenheads dot com
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: OS X 10.3.6
PHP Version: 5.0.2
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
See also the PHP 5 migration guide:
http://de.php.net/manual/en/migration5.incompatible.php
Previous Comments:
------------------------------------------------------------------------
[2004-11-09 21:01:53] cfoster at frozenheads dot com
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 this bug report at http://bugs.php.net/?id=30737&edit=1