Skip to content

Commit fa686a5

Browse files
committed
Fix incomplete class serialization behavior
1 parent ba1868f commit fa686a5

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/WP_CLI/SearchReplacer.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace WP_CLI;
44

5+
use ArrayObject;
6+
57
class SearchReplacer {
68

79
private $from, $to;
@@ -87,9 +89,22 @@ private function _run( $data, $serialised, $recursion_level = 0, $visited_data =
8789
}
8890
}
8991

90-
elseif ( $this->recurse_objects && is_object( $data ) ) {
91-
foreach ( $data as $key => $value ) {
92-
$data->$key = $this->_run( $value, false, $recursion_level + 1, $visited_data );
92+
elseif ( $this->recurse_objects ) {
93+
if ( $data instanceof \__PHP_Incomplete_Class ) {
94+
$array = new ArrayObject( $data );
95+
\WP_CLI::warning(
96+
sprintf(
97+
'Skipping an uninitialized class "%s", replacements might not be complete.',
98+
$array['__PHP_Incomplete_Class_Name']
99+
)
100+
);
101+
return $data;
102+
}
103+
104+
if ( is_object( $data ) ) {
105+
foreach ( $data as $key => $value ) {
106+
$data->$key = $this->_run( $value, false, $recursion_level + 1, $visited_data );
107+
}
93108
}
94109
}
95110

0 commit comments

Comments
 (0)