serialize() casts numeric string keys to integers
| From: | eyal . t | Date: | Mon, 12 Nov 2012 07:18:23 +0000 |
| Subject: | serialize() casts numeric string keys to integers | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-319687@lists.php.net to get a copy of this message | ||
Hi all,
Was wondering whether the fact that serialize() casts numeric string keys to integers, is a bug, intended behaviour, or just something that is minor enough not to have bothered anyone yet?
<?php
$arr1 = array('1'=>'string key'); // '1' will be casted to 1
$arr2 = array(1=>'integer key');
$arr1_uns = unserialize(serialize($arr1)) ;
$arr2_uns = unserialize(serialize($arr2)) ;
var_dump($arr1_uns, $arr2_uns);
==============================
array(1) {
[1]=>
string(10) "string key"
}
array(1) {
[1]=>
string(11) "integer key"
}