|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-03-26 05:38 UTC] 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 ....
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 25 06:00:01 2025 UTC |
<?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..