diff --git a/src/Serializer/AbstractSerializer.php b/src/Serializer/AbstractSerializer.php index ec1389ac8..766175a9e 100644 --- a/src/Serializer/AbstractSerializer.php +++ b/src/Serializer/AbstractSerializer.php @@ -280,7 +280,7 @@ protected function serializeValue($value) */ protected function serializeCallable($callable): string { - if (\is_string($callable) && !\function_exists($callable)) { + if (\is_string($callable)) { return $callable; } @@ -292,7 +292,7 @@ protected function serializeCallable($callable): string if (\is_array($callable)) { $reflection = new \ReflectionMethod($callable[0], $callable[1]); $class = $reflection->getDeclaringClass(); - } elseif ($callable instanceof \Closure || (\is_string($callable) && \function_exists($callable))) { + } elseif ($callable instanceof \Closure) { $reflection = new \ReflectionFunction($callable); $class = null; } elseif (\is_object($callable) && method_exists($callable, '__invoke')) { diff --git a/tests/Serializer/AbstractSerializerTest.php b/tests/Serializer/AbstractSerializerTest.php index 43fadc722..025a3921f 100644 --- a/tests/Serializer/AbstractSerializerTest.php +++ b/tests/Serializer/AbstractSerializerTest.php @@ -539,6 +539,11 @@ public function serializableCallableProvider(): array 'callable' => $callableWithoutNamespaces, 'expected' => 'Lambda void {closure} [int|null param1_70ns]', ], + [ + // This is (a example of) a PHP provided function that is technically callable but we want to ignore that because it causes more false positives than it helps + 'callable' => 'header', + 'expected' => 'header', + ], [ 'callable' => __METHOD__, 'expected' => __METHOD__,