@@ -39,18 +39,6 @@ public function __debugInfo(): ?array
3939 return $ this ->objectToArray ($ this , false );
4040 }
4141
42- public function __serialize (): array
43- {
44- return $ this ->toArray ();
45- }
46-
47- /**
48- * @throws Exception
49- */
50- public function __unserialize (array $ data )
51- {
52- $ this ->fill ($ data );
53- }
5442
5543 public static function from (array |Arrayable $ data ): static
5644 {
@@ -82,14 +70,17 @@ public function fill(array $data): static
8270 $ value = $ data [$ camelCasePropertyName ] ?? ($ data [$ snakePropertyName ] ?? null );
8371 if ($ type ->isBuiltin () && !is_null ($ value )) {
8472 $ property ->setValue ($ this , $ value );
85- }
86- if (class_exists ($ type ->getName ())) {
73+ } elseif (PHP_VERSION_ID > 80100 && enum_exists ($ type ->getName ())) {
74+ $ property ->setValue ($ this , $ value );
75+ } elseif (class_exists ($ type ->getName ())) {
8776 if (is_array ($ value )) {
8877 $ instance = new ($ type ->getName ());
8978 if ($ instance instanceof Data) {
9079 $ instance ->fill ($ value );
9180 }
9281 $ property ->setValue ($ this , $ instance );
82+ } else {
83+ $ property ->setValue ($ this , $ value );
9384 }
9485 }
9586 }
@@ -121,7 +112,11 @@ protected function propertyToArray(object $object, bool $toSnake, ReflectionProp
121112 continue ;
122113 }
123114 $ name = $ toSnake ? Str::snake ($ property ->getName ()) : $ property ->getName ();
124- $ result [$ name ] = $ this ->forValue ($ property ->getValue ($ object ), $ toSnake );
115+ if ($ property ->isInitialized ($ object )) {
116+ $ result [$ name ] = $ this ->forValue ($ property ->getValue ($ object ), $ toSnake );
117+ } else {
118+ $ result [$ name ] = null ;
119+ }
125120 }
126121 return $ result ;
127122 }
@@ -156,7 +151,10 @@ protected function getReflectionClass(object|string $object): ReflectionClass
156151
157152 protected function getStaticReflection (): ReflectionClass
158153 {
159- return $ this ->_staticReflection ?? $ this ->getReflectionClass ($ this );
154+ if ($ this ->_staticReflection ) {
155+ return $ this ->_staticReflection ;
156+ }
157+ return $ this ->_staticReflection = $ this ->getReflectionClass ($ this );
160158 }
161159
162160 protected function isInsideProperty (ReflectionProperty $ property ): bool
0 commit comments