File tree Expand file tree Collapse file tree 4 files changed +49
-2
lines changed Expand file tree Collapse file tree 4 files changed +49
-2
lines changed Original file line number Diff line number Diff line change 33 preset : laravel
44 finder :
55 not-name :
6+ - Php84Test.php
67 - ReflectionClosurePhp80Test.php
78 - ReflectionClosurePhp81Test.php
89 - SerializerPhp81Test.php
Original file line number Diff line number Diff line change 1111 backupStaticProperties =" false" >
1212 <testsuites >
1313 <testsuite name =" Tests" >
14- <directory >tests</directory >
14+ <file >tests/ReflectionClosure1Test.php</file >
15+ <file >tests/ReflectionClosure2Test.php</file >
16+ <file >tests/ReflectionClosure3Test.php</file >
17+ <file >tests/ReflectionClosure4Test.php</file >
18+ <file >tests/ReflectionClosure5Test.php</file >
19+ <file >tests/SerializerTest.php</file >
20+ <file >tests/SignedSerializerTest.php</file >
21+ </testsuite >
22+ <testsuite name =" php81" >
23+ <file phpVersion =" 8.1.0" phpVersionOperator =" >=" >tests/ReflectionClosurePhp80Test.php</file >
24+ <file phpVersion =" 8.1.0" phpVersionOperator =" >=" >tests/ReflectionClosurePhp81Test.php</file >
25+ <file phpVersion =" 8.1.0" phpVersionOperator =" >=" >tests/SerializerPhp80Test.php</file >
26+ <file phpVersion =" 8.1.0" phpVersionOperator =" >=" >tests/SerializerPhp81Test.php</file >
27+ </testsuite >
28+ <testsuite name =" php84" >
29+ <file phpVersion =" 8.4.0" phpVersionOperator =" >=" >tests/Php84Test.php</file >
1530 </testsuite >
1631 </testsuites >
1732</phpunit >
Original file line number Diff line number Diff line change 1212use Laravel \SerializableClosure \Support \SelfReference ;
1313use Laravel \SerializableClosure \UnsignedSerializableClosure ;
1414use ReflectionObject ;
15+ use ReflectionProperty ;
1516use UnitEnum ;
1617
1718class Native implements Serializable
@@ -490,7 +491,7 @@ protected function mapByReference(&$data)
490491 }
491492
492493 foreach ($ reflection ->getProperties () as $ property ) {
493- if ($ property ->isStatic () || ! $ property ->getDeclaringClass ()->isUserDefined ()) {
494+ if ($ property ->isStatic () || ! $ property ->getDeclaringClass ()->isUserDefined () || $ this -> isVirtualProperty ( $ property ) ) {
494495 continue ;
495496 }
496497
@@ -511,4 +512,15 @@ protected function mapByReference(&$data)
511512 } while ($ reflection = $ reflection ->getParentClass ());
512513 }
513514 }
515+
516+ /**
517+ * Determine is virtual property.
518+ *
519+ * @param \ReflectionProperty $property
520+ * @return bool
521+ */
522+ protected function isVirtualProperty (ReflectionProperty $ property ): bool
523+ {
524+ return method_exists ($ property , 'isVirtual ' ) && $ property ->isVirtual ();
525+ }
514526}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ it ('can serialize class with virtual property ' , function () {
4+ $ c = new VirtualPropWithPhp84 ();
5+
6+ $ f = function () use ($ c ) {
7+ return $ c ;
8+ };
9+
10+ $ s1 = s ($ f );
11+
12+ expect ('test ' )->toBe ($ s1 ()->test );
13+ })->with ('serializers ' );
14+
15+ class VirtualPropWithPhp84 {
16+ public string $ test {
17+ get => 'test ' ;
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments