Re: Alias stdClass to DynamicObject?

From: Date: Wed, 08 Sep 2021 16:32:43 +0000
Subject: Re: Alias stdClass to DynamicObject?
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-116013@lists.php.net to get a copy of this message
On Wed, Sep 8, 2021 at 5:38 PM Mike Schinkel <mike@newclarity.net> wrote: > A couple more things; add a JSON_OUTPUT_DYNAMIC_OBJECT flag to > output to > DynamicObject for json_decode(), add a 3rd parameter for flags > to > var_export() for the same reason, a > 'return_dynamic_object' option for > unserialize(), and so on. > It would also be interesting to enter a user-defined class here to work as a reversed JsonSerializable. Could be a static factory method for all I care, and would omit the requirement of serialization libraries for "simple" things where you still want decent object typing. Could also work together with interfaces accepting properties, effectively making the result of json_decode an anonymous class that still adheres to an interface. In case of the custom 'deserialization' you can throw exceptions if the format is not correct. In the case of an anonymous class with an interface it could throw an exception if the structure doesn't match (possibly controlled by flags?).

« previous php.internals (#116013) next »