@@ -247,34 +247,33 @@ int tokenPosition
247247
248248 private object MakeClass ( in PhpToken token ) {
249249 var typeName = this . GetString ( token ) ;
250- object constructedObject ;
251250 Type targetType = null ;
252251 if ( typeName != "stdClass" && this . _options . EnableTypeLookup ) {
253252 targetType = TypeLookup . FindTypeInAssymbly ( typeName , this . _options . TypeCache . HasFlag ( TypeCacheFlag . ClassNames ) ) ;
254253 }
255- if ( targetType != null && typeName != "stdClass" ) {
256- _currentToken -- ; // go back one because we're basically re-entering the object-token from the top.
257- // If we don't decrement the pointer, we'd start with the first child token instead of the object token.
258- constructedObject = this . DeserializeToken ( targetType ) ;
259- } else {
260- dynamic result ;
254+ if ( targetType == null || typeName == "stdClass" ) {
261255 if ( _options . StdClass == StdClassOption . Dynamic ) {
262- result = new PhpDynamicObject ( ) ;
256+ var result = new PhpDynamicObject ( token . Length , typeName ) ;
257+ result . SetClassName ( typeName ) ;
258+ for ( int i = 0 ; i < token . Length ; i ++ ) {
259+ result . TryAdd ( ( string ) this . DeserializeToken ( ) , this . DeserializeToken ( ) ) ;
260+ }
261+ return result ;
263262 } else if ( this . _options . StdClass == StdClassOption . Dictionary ) {
264- result = new PhpObjectDictionary ( ) ;
263+ var result = new PhpObjectDictionary ( token . Length , typeName ) ;
264+ result . SetClassName ( typeName ) ;
265+ for ( int i = 0 ; i < token . Length ; i ++ ) {
266+ result . TryAdd ( ( string ) this . DeserializeToken ( ) , this . DeserializeToken ( ) ) ;
267+ }
268+ return result ;
265269 } else {
266270 throw new DeserializationException ( "Encountered 'stdClass' and the behavior 'Throw' was specified in deserialization options." ) ;
267271 }
268- for ( int i = 0 ; i < token . Length ; i ++ ) {
269- var key = this . DeserializeToken ( ) ;
270- var value = this . DeserializeToken ( ) ;
271- result . TryAdd (
272- ( string ) key ,
273- value
274- ) ;
275- }
276- constructedObject = result ;
277272 }
273+ // go back one because we're basically re-entering the object-token from the top.
274+ // If we don't decrement the pointer, we'd start with the first child token instead of the object token.
275+ _currentToken -- ;
276+ var constructedObject = this . DeserializeToken ( targetType ) ;
278277 if ( constructedObject is IPhpObject phpObject and not PhpDateTime ) {
279278 phpObject . SetClassName ( typeName ) ;
280279 }
0 commit comments