From 97712d0fe1a97acd679c887feed1a8db807d7824 Mon Sep 17 00:00:00 2001 From: mark burdett Date: Fri, 17 May 2024 21:10:29 -0700 Subject: [PATCH 1/3] Represent callable strings as strings (#1734) --- src/Serializer/AbstractSerializer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serializer/AbstractSerializer.php b/src/Serializer/AbstractSerializer.php index ec1389ac8..b57a77424 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; } From 31be4e0291f56f39984beaebf518993ee2953379 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 27 May 2024 11:13:22 +0200 Subject: [PATCH 2/3] Add test --- tests/Serializer/AbstractSerializerTest.php | 5 +++++ 1 file changed, 5 insertions(+) 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__, From 84d184e965ec54be311d9ed3c928f31ba16bafbd Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 27 May 2024 11:13:58 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Remove=20condition=20that=20can=E2=80=99t?= =?UTF-8?q?=20be=20reached?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Serializer/AbstractSerializer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serializer/AbstractSerializer.php b/src/Serializer/AbstractSerializer.php index b57a77424..766175a9e 100644 --- a/src/Serializer/AbstractSerializer.php +++ b/src/Serializer/AbstractSerializer.php @@ -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')) {