diff --git a/src/Psalm/Internal/Codebase/Functions.php b/src/Psalm/Internal/Codebase/Functions.php index a05723d923f..eb73c2932be 100644 --- a/src/Psalm/Internal/Codebase/Functions.php +++ b/src/Psalm/Internal/Codebase/Functions.php @@ -518,12 +518,27 @@ public function isCallMapFunctionPure( //gettext 'bindtextdomain', + + // unserialize + 'unserialize' ]; if (in_array(strtolower($function_id), $impure_functions, true)) { return false; } + if ($function_id === 'serialize' && isset($args[0]) && $type_provider) { + $serialize_type = $type_provider->getType($args[0]->value); + + if ($serialize_type) { + foreach ($serialize_type->getAtomicTypes() as $atomic_serialize_type) { + if ($atomic_serialize_type->isObjectType()) { + return false; + } + } + } + } + if (strpos($function_id, 'image') === 0) { return false; } diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 341de7fe61c..373ad1cf72b 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -737,6 +737,31 @@ public function unserialize($_serialized) : void {} new Foo();' ], + 'ignoreSerializeAndUnserialize' => [ + ' [ '