From:             tobias at gaszmann dot de
Operating system: WIN32 and Linux
PHP version:      5.2.6
PHP Bug Type:     Feature/Change Request
Bug description:  Its not a bug, its a feature, but a problem.

Description:
------------
Associative Arrays loose their "string-but-numbers-only-keys" when being
merged.

array_something["34"]="hello 34";
will get lost when being array_merged.

array_something["34_ID"]="hello 34";
will be ok when being array_merged.

I know this is most likely a feature, but it really did threw me off and
took a while to get down to. To me this is an unwanted behavior.

Even more so, as you cannot force the array to remain associative, even
not by "(string)" or settype, as you can see in the demo-code. 

Thank you!
Tobias Gassmann


Reproduce code:
---------------
$array_one=array();
$array_one["one"]   = "Database-Entry with UID='one'";
$array_one["2_uid"] = "Database-Entry with UID='2_uid'";
$array_one["ID_3"]  = "Database-Entry with UID='ID_3'";
print_r($array_one);

$array_two=array();
$array_two["four"]  = "Database-Entry with UID='four'";
$array_two["5"]     = "Database-Entry with UID='5'";
$string_six="6";
$array_two["$string_six"] = "Database-Entry with UID='6'";
$string_seven="7";
settype($string_seven,"string");
$array_two["$string_seven"] = "Database-Entry with UID='7'";
$array_two["ID_8"]  = "Database-Entry with UID='ID_8'";
print_r($array_two);

$array_three = array_merge($array_one,$array_two);
print_r($array_three);


Expected result:
----------------
I would have expected for all keys to remain what they are. 

Actual result:
--------------
The keys "5", "6" and "7" got lost, although I declared them as strings.

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

Reply via email to