From: scribu Date: Tue, 23 Jul 2013 19:03:53 +0000 (+0300) Subject: clone object instead of calling constructor; fixes #592 X-Git-Tag: v0.11.0~27 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ef051f9dcfddf3384b98a977a6588a74e468fe9f;p=wvm%2Fwvm.git clone object instead of calling constructor; fixes #592 --- diff --git a/php/utils.php b/php/utils.php index 8b8c463f..0bb98f1d 100644 --- a/php/utils.php +++ b/php/utils.php @@ -217,19 +217,15 @@ function recursive_unserialize_replace( $from = '', $to = '', $data = '', $seria } $data = $_tmp; - unset( $_tmp ); } - // Submitted by Tina Matter elseif ( is_object( $data ) ) { - $dataClass = get_class( $data ); - $_tmp = new $dataClass( ); + $_tmp = clone( $data ); foreach ( $data as $key => $value ) { $_tmp->$key = recursive_unserialize_replace( $from, $to, $value, false ); } $data = $_tmp; - unset( $_tmp ); } else { @@ -255,7 +251,7 @@ function recursive_unserialize_replace( $from = '', $to = '', $data = '', $seria * @param array|string $fields Named fields for each item of data. Can be array or comma-separated list */ function format_items( $format, $items, $fields ) { - + if ( 'ids' == $format ) { echo implode( ' ', $items ); return; diff --git a/tests/test-unserialize-replace.php b/tests/test-unserialize-replace.php new file mode 100644 index 00000000..3389336f --- /dev/null +++ b/tests/test-unserialize-replace.php @@ -0,0 +1,24 @@ +assertEquals( 'bar', $new_obj->prop ); + } +} + + +class ClassWithPrivateConstructor { + + public $prop = 'foo'; + + private function __construct() {} + + public static function get_instance() { + return new self; + } +} +