From 970824e4a779e20bfda5bb52721ba2f31ec1ae7f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 11 Feb 2025 20:44:30 +0800 Subject: [PATCH 1/6] wip Signed-off-by: Mior Muhammad Zaki --- phpunit.xml.dist | 17 ++++++++++++++++- tests/Php84Test.php | 0 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/Php84Test.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index be7f586e..6ac2c189 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,22 @@ backupStaticProperties="false"> - tests + tests/ReflectionClosure1Test.php + tests/ReflectionClosure2Test.php + tests/ReflectionClosure3Test.php + tests/ReflectionClosure4Test.php + tests/ReflectionClosure5Test.php + tests/SerializerTest.php + tests/SignedSerializerTest.php + + + tests/ReflectionClosurePhp80Test.php + tests/ReflectionClosurePhp81Test.php + tests/SerializerPhp80Test.php + tests/SerializerPhp81Test.php + + + tests/Php84Test.php diff --git a/tests/Php84Test.php b/tests/Php84Test.php new file mode 100644 index 00000000..e69de29b From 39533c2f5d52e56eb17ae73965ef1898824525f9 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 11 Feb 2025 20:53:00 +0800 Subject: [PATCH 2/6] wip Signed-off-by: Mior Muhammad Zaki --- src/Serializers/Native.php | 14 +++++++++++++- tests/Php84Test.php | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Serializers/Native.php b/src/Serializers/Native.php index 8264c324..4747698b 100644 --- a/src/Serializers/Native.php +++ b/src/Serializers/Native.php @@ -12,6 +12,7 @@ use Laravel\SerializableClosure\Support\SelfReference; use Laravel\SerializableClosure\UnsignedSerializableClosure; use ReflectionObject; +use ReflectionProperty; use UnitEnum; class Native implements Serializable @@ -490,7 +491,7 @@ protected function mapByReference(&$data) } foreach ($reflection->getProperties() as $property) { - if ($property->isStatic() || ! $property->getDeclaringClass()->isUserDefined()) { + if ($property->isStatic() || $this->isVirtualProperty($property) || ! $property->getDeclaringClass()->isUserDefined()) { continue; } @@ -511,4 +512,15 @@ protected function mapByReference(&$data) } while ($reflection = $reflection->getParentClass()); } } + + /** + * Determine is virtual property. + * + * @param \ReflectionProperty $property + * @return bool + */ + protected function isVirtualProperty(ReflectionProperty $property): bool + { + return method_exists($property, 'isVirtual') && $property->isVirtual(); + } } diff --git a/tests/Php84Test.php b/tests/Php84Test.php index e69de29b..44737c39 100644 --- a/tests/Php84Test.php +++ b/tests/Php84Test.php @@ -0,0 +1,19 @@ +toBe($s1()->test); +})->with('serializers'); + +class VirtualPropWithPhp84 { + public string $test { + get => 'test'; + } +} From 25ab13a957c3c24542da6b53d34508e6871bc420 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 11 Feb 2025 20:55:24 +0800 Subject: [PATCH 3/6] wip Signed-off-by: Mior Muhammad Zaki --- .styleci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index d48472a8..8c0de246 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -3,6 +3,4 @@ php: preset: laravel finder: not-name: - - ReflectionClosurePhp80Test.php - - ReflectionClosurePhp81Test.php - - SerializerPhp81Test.php + - Php84Test.php From 6b3ea42f2eb671d7147c1def48b4c1bad90e7448 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 11 Feb 2025 20:57:42 +0800 Subject: [PATCH 4/6] wip Signed-off-by: Mior Muhammad Zaki --- src/Serializers/Native.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Serializers/Native.php b/src/Serializers/Native.php index 4747698b..6e8febd0 100644 --- a/src/Serializers/Native.php +++ b/src/Serializers/Native.php @@ -491,7 +491,7 @@ protected function mapByReference(&$data) } foreach ($reflection->getProperties() as $property) { - if ($property->isStatic() || $this->isVirtualProperty($property) || ! $property->getDeclaringClass()->isUserDefined()) { + if ($property->isStatic() || ! $property->getDeclaringClass()->isUserDefined()) { continue; } @@ -501,6 +501,10 @@ protected function mapByReference(&$data) continue; } + if ($this->isVirtualProperty($property)) { + continue; + } + $value = $property->getValue($instance); if (is_array($value) || is_object($value)) { From 705f42129f8dea147b89157817cad152f5890671 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 11 Feb 2025 21:00:11 +0800 Subject: [PATCH 5/6] wip Signed-off-by: Mior Muhammad Zaki --- .styleci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.styleci.yml b/.styleci.yml index 8c0de246..6f2e70a5 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -4,3 +4,6 @@ php: finder: not-name: - Php84Test.php + - ReflectionClosurePhp80Test.php + - ReflectionClosurePhp81Test.php + - SerializerPhp81Test.php From 01dad18a6f09fb676217813248fc70ef832605fa Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 11 Feb 2025 21:02:59 +0800 Subject: [PATCH 6/6] wip Signed-off-by: Mior Muhammad Zaki --- src/Serializers/Native.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Serializers/Native.php b/src/Serializers/Native.php index 6e8febd0..6fe884bb 100644 --- a/src/Serializers/Native.php +++ b/src/Serializers/Native.php @@ -491,7 +491,7 @@ protected function mapByReference(&$data) } foreach ($reflection->getProperties() as $property) { - if ($property->isStatic() || ! $property->getDeclaringClass()->isUserDefined()) { + if ($property->isStatic() || ! $property->getDeclaringClass()->isUserDefined() || $this->isVirtualProperty($property)) { continue; } @@ -501,10 +501,6 @@ protected function mapByReference(&$data) continue; } - if ($this->isVirtualProperty($property)) { - continue; - } - $value = $property->getValue($instance); if (is_array($value) || is_object($value)) {