diff --git a/.styleci.yml b/.styleci.yml index d48472a8..6f2e70a5 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -3,6 +3,7 @@ php: preset: laravel finder: not-name: + - Php84Test.php - ReflectionClosurePhp80Test.php - ReflectionClosurePhp81Test.php - SerializerPhp81Test.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/src/Serializers/Native.php b/src/Serializers/Native.php index 8264c324..6fe884bb 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() || ! $property->getDeclaringClass()->isUserDefined() || $this->isVirtualProperty($property)) { 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 new file mode 100644 index 00000000..44737c39 --- /dev/null +++ b/tests/Php84Test.php @@ -0,0 +1,19 @@ +toBe($s1()->test); +})->with('serializers'); + +class VirtualPropWithPhp84 { + public string $test { + get => 'test'; + } +}