|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-07-22 11:56 UTC] ralf dot praschak at gmx dot net
Description:
------------
for exchanging a screenshot gallery i decode every exif information in a wddx packet. worked without problems in php4.3.x under win32 and linux.
now with php5.0.0, the wddx is generated proberly but cannot deserialized. if i reduce the size of the hash, it works, but that is not a solution. the error.log from apache shows nothing hintful.
Reproduce code:
---------------
1. the wddx generation
// save the cache file
$wddx = wddx_packet_start("Screenshots");
wddx_add_vars($wddx, "sort");
$wddx = wddx_packet_end($wddx);
$wddx = addslashes($wddx);
$file = $_cache."_includes/screenshots.wddx.php";
$fp = fopen($file, "w");
fwrite($fp, $wddx);
fclose($fp);
2. the deserialize process
// read wddx cache file
$wddx = file_get_contents($_cache."_includes/screenshots.wddx.php");
$wddx = stripslashes($wddx);
$wddx = wddx_deserialize($wddx);
$wddx = $wddx["sort"];
Expected result:
----------------
an array with the original hash
Actual result:
--------------
an empty result
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 03:00:01 2025 UTC |
I am also having difficulty with deserialize. If I take an array and run wddx_serialize_vars("thisarr"). Then take the result and deserialize it, any array keys that are numbers produce a "no such index" when dereferencing. I was able to work around the problem with the following: function SanitizeArray ($arr) { if (!is_array($arr)) { return $arr; }; while (list($key,$val) = each($arr) ){ if (is_array($val)) { $val = SanitizeArray($val); }; $rtn[$key] = $val; }; return $rtn; }; array keys that were strings did not have any problems.More info on my previous note. Sample code: ------------------------------------------------------------- <? function SanitizeArray ($arr) { if (!is_array($arr)) { return $arr; }; while (list($key,$val) = each($arr) ){ if (is_array($val)) { $val = SanitizeArray($val); }; $rtn[$key] = $val; }; return $rtn; }; $test = array( 0 =>array( 'me' => "you" ), 'one' => array( 'me' => "you" ) ); print "<PRE>"; var_dump($test); print $test[0]['me'] . "\n"; print $test['0']['me'] . "\n"; print $test['one']['me'] . "\n"; $ddx = wddx_serialize_vars("test"); $after = wddx_deserialize($ddx); var_dump($after['test']); print $after['test'][0]['me'] . "\n"; print $after['test']['0']['me'] . "\n"; print $after['test']['one']['me'] . "\n"; list($key,$val) = each($after['test']); print gettype($key); $clean = SanitizeArray($after); var_dump($clean['test']); print $clean['test'][0]['me'] . "\n"; print $clean['test']['0']['me'] . "\n"; print $clean['test']['one']['me'] . "\n"; list($key,$val) = each($after['test']); print gettype($key); print "</PRE>"; phpinfo(); ?> ----------------------------------------------------------- Produces: array(2) { [0]=> array(1) { ["me"]=> string(3) "you" } ["one"]=> array(1) { ["me"]=> string(3) "you" } } you you you array(2) { ["0"]=> array(1) { ["me"]=> string(3) "you" } ["one"]=> array(1) { ["me"]=> string(3) "you" } } Notice: Undefined offset: 0 in C:\Program Files\Apache Group\Apache2\htdocs\syncit\test.php on line 27 Notice: Undefined index: 0 in C:\Program Files\Apache Group\Apache2\htdocs\syncit\test.php on line 28 you stringarray(2) { [0]=> array(1) { ["me"]=> string(3) "you" } ["one"]=> array(1) { ["me"]=> string(3) "you" } } you you you string ----------------------------------------------------------- PHP Version 5.0.0 Windows NT COUNTER-3 5.0 build 2195 Build Date: Jul 13 2004 21:34:42I am using 5.0.3-DEV (Stable Snapshot 200411161730). Deserialization works fine for objects that are all public. However as soon as the object has private or protected member variables, the result bombs. Sample code: (Failure Only) --------------------------- try { throw new Exception ("FooBar", 1111); } catch (Exception $e) { $s = wddx_serialize_value ($e); } $t = wddx_deserialize($s); print_r ($t); ---------------- Expected Result: ---------------- Exception Object ( [message:protected] => FooBar [string:private] => [code:protected] => 1111 [file:protected] => /virtualhosts/test/wddx3.php [line:protected] => 4 [trace:private] => Array ( ) ) -------------- Actual Result: -------------- Exception Object ( [message:protected] => [string:private] => [code:protected] => 0 [file:protected] => /virtualhosts/test/wddx3.php [line:protected] => 16 [trace:private] => Array ( ) [0] => FooBar [1] => [2] => 1111 [3] => /virtualhosts/test/wddx3.php [4] => 4 [5] => Array ( ) )