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 3
3
preset : laravel
4
4
finder :
5
5
not-name :
6
+ - Php84Test.php
6
7
- ReflectionClosurePhp80Test.php
7
8
- ReflectionClosurePhp81Test.php
8
9
- SerializerPhp81Test.php
Original file line number Diff line number Diff line change 11
11
backupStaticProperties =" false" >
12
12
<testsuites >
13
13
<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 >
15
30
</testsuite >
16
31
</testsuites >
17
32
</phpunit >
Original file line number Diff line number Diff line change 12
12
use Laravel \SerializableClosure \Support \SelfReference ;
13
13
use Laravel \SerializableClosure \UnsignedSerializableClosure ;
14
14
use ReflectionObject ;
15
+ use ReflectionProperty ;
15
16
use UnitEnum ;
16
17
17
18
class Native implements Serializable
@@ -490,7 +491,7 @@ protected function mapByReference(&$data)
490
491
}
491
492
492
493
foreach ($ reflection ->getProperties () as $ property ) {
493
- if ($ property ->isStatic () || ! $ property ->getDeclaringClass ()->isUserDefined ()) {
494
+ if ($ property ->isStatic () || ! $ property ->getDeclaringClass ()->isUserDefined () || $ this -> isVirtualProperty ( $ property ) ) {
494
495
continue ;
495
496
}
496
497
@@ -511,4 +512,15 @@ protected function mapByReference(&$data)
511
512
} while ($ reflection = $ reflection ->getParentClass ());
512
513
}
513
514
}
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
+ }
514
526
}
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