From 42956b66459ae7e94ea37bd87b6302ec848d5bf3 Mon Sep 17 00:00:00 2001 From: Lars Heber Date: Fri, 13 Oct 2023 08:19:45 +0200 Subject: [PATCH] Keep BC compat to PHP 7: Don't use "::class" on dynamic class names #58 --- .../ClosureSerializer/ClosureSerializerManager.php | 3 ++- src/JsonSerializer/JsonSerializer.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/JsonSerializer/ClosureSerializer/ClosureSerializerManager.php b/src/JsonSerializer/ClosureSerializer/ClosureSerializerManager.php index 8fb8443..3a1bd20 100644 --- a/src/JsonSerializer/ClosureSerializer/ClosureSerializerManager.php +++ b/src/JsonSerializer/ClosureSerializer/ClosureSerializerManager.php @@ -27,7 +27,8 @@ class ClosureSerializerManager { */ public function addSerializer(ClosureSerializer $closureSerializer) { - $classname = $closureSerializer::class; + // Keep BC compat to PHP 7: Don't use "::class" on dynamic class names + $classname = get_class($closureSerializer); $this->closureSerializer[$classname] = $closureSerializer; return $this; } diff --git a/src/JsonSerializer/JsonSerializer.php b/src/JsonSerializer/JsonSerializer.php index b478293..1d51814 100644 --- a/src/JsonSerializer/JsonSerializer.php +++ b/src/JsonSerializer/JsonSerializer.php @@ -264,7 +264,8 @@ protected function serializeData($value) } return [ static::CLOSURE_IDENTIFIER_KEY => true, - 'serializer' => $closureSerializer::class, + // Keep BC compat to PHP 7: Don't use "::class" on dynamic class names + 'serializer' => get_class($closureSerializer), 'value' => $closureSerializer->serialize($value) ]; }