ID: 27712
User updated by: hannes at phpug dot ch
Reported By: hannes at phpug dot ch
Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5CVS-2004-04-07
New Comment:
Yous see, the example string above does not come from PHP. Other tools
that interact with PHP have adopted the format. The string above can be
unserialized in PHP4 and in PHP5, the result can not be accessed using
the indices.
If you feel this is not PHP's fault, just close this bug. :)
Previous Comments:
------------------------------------------------------------------------
[2004-04-07 07:49:09] [EMAIL PROTECTED]
<?php
error_reporting(E_ALL);
$nam = array ("0" => "hubert", "1" => "waldo");
$ser = serialize ($nam);
echo $ser, "\n";
$unser = unserialize ($ser);
var_export($unser);
?>
Using that script, I can NOT get such serialized string as you did.
Note: There was some bug in this earlier but nowadays serialize() works
fine..
------------------------------------------------------------------------
[2004-03-26 05:38:54] hannes at phpug dot ch
Description:
------------
Unserialize works perfectly and produces an array with like
array("0" => "foo"). The same serialized string gets unserialized
differently in PHP4, there it's array(0 => "foo").
I cannot access the content of the PHP5 result, because it seems that
my lookup for "1"(string) gets converted to one for 1 (int). Which
fails.
Tested with:
-PHP 4.3.5RC2-dev (cli) (built: Jan 15 2004 16:58:31)
-PHP 5.0.0RC2-dev (cli) (built: Mar 21 2004 17:58:48)
I'm not sure if this is really something that needs to be fixed,
unserialize works correctly, but not as expected.
Reproduce code:
---------------
<?php
error_reporting(E_ALL);
$serializedNames = 'a:2:{s:1:"0";s:6:"hubert";s:1:"1";s:5:"waldo";}';
$names = unserialize($serializedNames);
var_export($names); //works, but...
/*
php5:
array (
'0' => 'hubert',
php4:
array (
0 => 'hubert',
..
print($names["1"]); // php5: doesn't work. php4: works;
print($names[1]); // php5: doesn't work php4: works;
?>
Expected result:
----------------
array (
0 => 'hubert',
1 => 'waldo',
)waldowaldo
Actual result:
--------------
array (
'0' => 'hubert',
'1' => 'waldo',
)
PHP Notice: Undefined index: 1 in ....
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27712&edit=1