Permalink
Browse files

fixed phpsh to work with objects implementing Serializable

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...
1 parent 8c37afe commit a1138c3499626394f1bf9670b656d43e1e1040bc Dmitri Petrov committed May 18, 2010
Showing with 8 additions and 9 deletions.
  1. +8 −9 src/phpsh.php
View
17 src/phpsh.php
@@ -223,17 +223,16 @@ function ___phpsh___parse_dump_obj_lines($x, $dump, &$pos, $arr_len, $depth,
return $arr_lines;
}
function ___phpsh___obj_to_arr($x) {
- $x_ser = serialize($x);
- $x_ser = substr($x_ser, strpos($x_ser, ':', 3) + 1);
- $x_ser = 'a'.substr($x_ser, strpos($x_ser, ':'));
- $x_arr = array();
- foreach (unserialize($x_ser) as $k => $v) {
- if ($k[0] == "\000") {
- $k = substr($k, strpos($k, "\000", 2) + 1);
+ if (is_object($x)) {
+ $raw_array = (array)$x;
+ $result = array();
+ foreach ($raw_array as $key => $value) {
+ $key = preg_replace('/\\000.*\\000/', '', $key);
+ $result[$key] = $value;
}
- $x_arr[$k] = $v;
+ return $result;
}
- return $x_arr;
+ return (array)$x;
}
function ___phpsh___parse_dump_assert($dump, &$pos, $str, $end=false) {
$len = strlen($str);

0 comments on commit a1138c3

Please sign in to comment.