|
2 | 2 |
|
3 | 3 | namespace WP_CLI;
|
4 | 4 |
|
| 5 | +use ArrayObject; |
5 | 6 | use Exception;
|
6 | 7 |
|
7 | 8 | class SearchReplacer {
|
@@ -89,9 +90,19 @@ private function _run( $data, $serialised, $recursion_level = 0, $visited_data =
|
89 | 90 | }
|
90 | 91 | }
|
91 | 92 |
|
92 |
| - elseif ( $this->recurse_objects && is_object( $data ) ) { |
93 |
| - foreach ( $data as $key => $value ) { |
94 |
| - $data->$key = $this->_run( $value, false, $recursion_level + 1, $visited_data ); |
| 93 | + elseif ( $this->recurse_objects && ( is_object( $data ) || $data instanceof \__PHP_Incomplete_Class ) ) { |
| 94 | + if ( $data instanceof \__PHP_Incomplete_Class ) { |
| 95 | + $array = new ArrayObject( $data ); |
| 96 | + \WP_CLI::warning( |
| 97 | + sprintf( |
| 98 | + 'Skipping an uninitialized class "%s", replacements might not be complete.', |
| 99 | + $array['__PHP_Incomplete_Class_Name'] |
| 100 | + ) |
| 101 | + ); |
| 102 | + } else { |
| 103 | + foreach ( $data as $key => $value ) { |
| 104 | + $data->$key = $this->_run( $value, false, $recursion_level + 1, $visited_data ); |
| 105 | + } |
95 | 106 | }
|
96 | 107 | }
|
97 | 108 |
|
@@ -155,13 +166,19 @@ public function clear_log_data() {
|
155 | 166 | * @return string Error constant name.
|
156 | 167 | */
|
157 | 168 | private function preg_error_message( $error ) {
|
158 |
| - $constants = get_defined_constants( true ); |
159 |
| - if ( ! array_key_exists( 'pcre', $constants ) ) { |
160 |
| - return '<unknown error>'; |
| 169 | + static $error_names = null; |
| 170 | + |
| 171 | + if ( null === $error_names ) { |
| 172 | + $definitions = get_defined_constants( true ); |
| 173 | + $pcre_constants = array_key_exists( 'pcre', $definitions ) |
| 174 | + ? $definitions['pcre'] |
| 175 | + : array(); |
| 176 | + $error_names = array_flip( $pcre_constants ); |
161 | 177 | }
|
162 | 178 |
|
163 |
| - $names = array_flip( $constants['pcre'] ); |
164 |
| - return isset( $names[ $error ] ) ? $names[ $error ] : '<unknown error>'; |
| 179 | + return isset( $error_names[ $error ] ) |
| 180 | + ? $error_names[ $error ] |
| 181 | + : '<unknown error>'; |
165 | 182 | }
|
166 | 183 | }
|
167 | 184 |
|
0 commit comments