ID: 29323
Comment by: pauls at sellingsource dot com
Reported By: ralf dot praschak at gmx dot net
Status: Open
Bug Type: WDDX related
Operating System: windows 2000 professional sp4
PHP Version: 5.0.0
New Comment:
I 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
(
)
)
Previous Comments:
------------------------------------------------------------------------
[2004-11-18 19:22:41] php at mojeime dot com
There is a BUG. And a major one.
The most interesting aspect of this bug is that the deserialization
works perfectly under Zend Development Environment (3.5.0) but does not
work under my Apache 2.50 /PHP5.0.2. I'm using Win2003.
But the problem isn't in Apache (it seems), because the same bug occurs
when I run my .php file with php.exe.
DO SOMETHING!!!
------------------------------------------------------------------------
[2004-10-16 23:08:43] php at stew dot org
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:42
------------------------------------------------------------------------
[2004-10-16 22:39:54] php at stew dot org
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.
------------------------------------------------------------------------
[2004-09-06 17:43:51] s dot lemke at infoworxx dot de
I experienced the same behaviour with php 5.0.1 running on
linux/apache.
------------------------------------------------------------------------
[2004-07-22 11:56:01] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29323&edit=1