diff --git a/src/Psalm/Checker/FunctionChecker.php b/src/Psalm/Checker/FunctionChecker.php index 76656ee1a..18bffee40 100644 --- a/src/Psalm/Checker/FunctionChecker.php +++ b/src/Psalm/Checker/FunctionChecker.php @@ -135,6 +135,22 @@ class FunctionChecker extends FunctionLikeChecker return $call_map_key === 'var_export' ? Type::getVoid() : Type::getBool(); + case 'print_r': + if (isset($call_args[1]->value->inferredType)) { + $subject_type = $call_args[1]->value->inferredType; + + if ((string) $subject_type === 'true') { + return Type::getString(); + } + + return new Type\Union([ + new Type\Atomic\TString, + new Type\Atomic\TTrue + ]); + } + + return Type::getTrue(); + case 'getenv': return new Type\Union([new Type\Atomic\TString, new Type\Atomic\TFalse]); diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 2a933c757..ed360bf16 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -960,6 +960,14 @@ class FunctionCallTest extends TestCase '$d' => 'array', ], ], + 'printrOutput' => [ + '