Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
fixed phpsh to work with objects implementing Serializable
Browse files Browse the repository at this point in the history
Summary: current implementation of phpsh usese serialize/unserialize
cycle and some hacks to convert an object into an array. This fails if
the object's class implements the Serializable interface and uses custom
serialization (hacks dont' work). I have fixed this problem by instead
casting objects to arrays and demangiling private and protected key
names.
  • Loading branch information
Dmitri Petrov committed May 18, 2010
1 parent 8c37afe commit a1138c3
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/phpsh.php
Expand Up @@ -223,17 +223,16 @@ function ___phpsh___parse_dump_obj_lines($x, $dump, &$pos, $arr_len, $depth,
return $arr_lines; return $arr_lines;
} }
function ___phpsh___obj_to_arr($x) { function ___phpsh___obj_to_arr($x) {
$x_ser = serialize($x); if (is_object($x)) {
$x_ser = substr($x_ser, strpos($x_ser, ':', 3) + 1); $raw_array = (array)$x;
$x_ser = 'a'.substr($x_ser, strpos($x_ser, ':')); $result = array();
$x_arr = array(); foreach ($raw_array as $key => $value) {
foreach (unserialize($x_ser) as $k => $v) { $key = preg_replace('/\\000.*\\000/', '', $key);
if ($k[0] == "\000") { $result[$key] = $value;
$k = substr($k, strpos($k, "\000", 2) + 1);
} }
$x_arr[$k] = $v; return $result;
} }
return $x_arr; return (array)$x;
} }
function ___phpsh___parse_dump_assert($dump, &$pos, $str, $end=false) { function ___phpsh___parse_dump_assert($dump, &$pos, $str, $end=false) {
$len = strlen($str); $len = strlen($str);
Expand Down

0 comments on commit a1138c3

Please sign in to comment.