@@ -139,9 +139,9 @@ private function dumpArray(array &$var, array $parents, int $level, int $column)
139139 private function dumpObject (object $ var , array $ parents , int $ level ): string
140140 {
141141 $ class = $ var ::class;
142- if ( method_exists ( $ var , ' __serialize ' )) {
143- $ data = $ this -> dump ( $ var -> __serialize ());
144- return '\\' . self :: class . " ::createObject( \\ $ class ::class , $ data ) " ;
142+
143+ if ( in_array ( $ class , [\DateTime::class, \DateTimeImmutable::class], true )) {
144+ return $ this -> format ( " new \\ $ class(?, new \\ DateTimeZone(?)) " , $ var -> format ( ' Y-m-d H:i:s.u ' ) , $ var -> getTimeZone ()-> getName ()) ;
145145
146146 } elseif ($ var instanceof \Serializable) { // deprecated
147147 return 'unserialize( ' . $ this ->dumpString (serialize ($ var )) . ') ' ;
@@ -158,29 +158,28 @@ private function dumpObject(object $var, array $parents, int $level): string
158158 }
159159
160160 throw new Nette \InvalidArgumentException ('Cannot dump closure. ' );
161- }
162161
163- if ((new \ReflectionObject ($ var ))->isAnonymous ()) {
162+ } elseif ((new \ReflectionObject ($ var ))->isAnonymous ()) {
164163 throw new Nette \InvalidArgumentException ('Cannot dump anonymous class. ' );
165164
166- } elseif (in_array ($ class , [\DateTime::class, \DateTimeImmutable::class] , true )) {
167- return $ this -> format ( " new \\ $ class (?, new \\ DateTimeZone(?)) " , $ var -> format ( ' Y-m-d H:i:s.u ' ), $ var -> getTimeZone ()-> getName () );
165+ } elseif ($ level > $ this -> maxDepth || in_array ($ var , $ parents , true )) {
166+ throw new Nette \ InvalidArgumentException ( ' Nesting level too deep or recursive dependency. ' );
168167 }
169168
170- $ arr = (array ) $ var ;
171- $ space = str_repeat ($ this ->indentation , $ level );
172-
173- if ($ level > $ this ->maxDepth || in_array ($ var , $ parents , true )) {
174- throw new Nette \InvalidArgumentException ('Nesting level too deep or recursive dependency. ' );
169+ if (method_exists ($ var , '__serialize ' )) {
170+ $ arr = $ var ->__serialize ();
171+ } else {
172+ $ arr = (array ) $ var ;
173+ if (method_exists ($ var , '__sleep ' )) {
174+ foreach ($ var ->__sleep () as $ v ) {
175+ $ props [$ v ] = $ props ["\x00* \x00$ v " ] = $ props ["\x00$ class \x00$ v " ] = true ;
176+ }
177+ }
175178 }
176179
180+ $ space = str_repeat ($ this ->indentation , $ level );
177181 $ out = "\n" ;
178182 $ parents [] = $ var ;
179- if (method_exists ($ var , '__sleep ' )) {
180- foreach ($ var ->__sleep () as $ v ) {
181- $ props [$ v ] = $ props ["\x00* \x00$ v " ] = $ props ["\x00$ class \x00$ v " ] = true ;
182- }
183- }
184183
185184 foreach ($ arr as $ k => &$ v ) {
186185 if (!isset ($ props ) || isset ($ props [$ k ])) {
@@ -195,7 +194,7 @@ private function dumpObject(object $var, array $parents, int $level): string
195194 $ out .= $ space ;
196195 return $ class === \stdClass::class
197196 ? "(object) [ $ out] "
198- : '\\' . self ::class . "::createObject(' $ class' , [$ out]) " ;
197+ : '\\' . self ::class . "::createObject( \\ $ class::class , [$ out]) " ;
199198 }
200199
201200
0 commit comments