Skip to content

Commit aff9a8f

Browse files
committed
skip deserialization of S&R objects that return TypeErrors
1 parent 0b662a3 commit aff9a8f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/WP_CLI/SearchReplacer.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,24 @@ private function run_recursively( $data, $serialised, $recursion_level = 0, $vis
8383
}
8484
}
8585

86-
// The error suppression operator is not enough in some cases, so we disable
87-
// reporting of notices and warnings as well.
88-
$error_reporting = error_reporting();
89-
error_reporting( $error_reporting & ~E_NOTICE & ~E_WARNING );
90-
$unserialized = is_string( $data ) ? @unserialize( $data ) : false;
91-
error_reporting( $error_reporting );
86+
try {
87+
// The error suppression operator is not enough in some cases, so we disable
88+
// reporting of notices and warnings as well.
89+
$error_reporting = error_reporting();
90+
error_reporting( $error_reporting & ~E_NOTICE & ~E_WARNING );
91+
$unserialized = is_string( $data ) ? @unserialize( $data ) : false;
92+
error_reporting($error_reporting);
93+
} catch (\TypeError $e) {
94+
// catch incompatible deserialized object type conversions between different PHP versions and skip them
95+
\WP_CLI::warning(
96+
sprintf(
97+
'Skipping an inconvertible serialized object: "%s", replacements might not be complete.',
98+
$data
99+
)
100+
);
101+
102+
$unserialized = false;
103+
}
92104

93105
if ( false !== $unserialized ) {
94106
$data = $this->run_recursively( $unserialized, true, $recursion_level + 1 );

0 commit comments

Comments
 (0)