}
$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 {
* @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;
--- /dev/null
+<?php
+
+class UnserializeReplaceTest extends PHPUnit_Framework_TestCase {
+
+ function testPrivateConstructor() {
+ $old_obj = ClassWithPrivateConstructor::get_instance();
+
+ $new_obj = WP_CLI\Utils\recursive_unserialize_replace( 'foo', 'bar', $old_obj );
+ $this->assertEquals( 'bar', $new_obj->prop );
+ }
+}
+
+
+class ClassWithPrivateConstructor {
+
+ public $prop = 'foo';
+
+ private function __construct() {}
+
+ public static function get_instance() {
+ return new self;
+ }
+}
+