Re: Is there any interest for object constructor shorthand *just forstdClass*

From: Date: Fri, 23 Oct 2020 20:53:23 +0000
Subject: Re: Is there any interest for object constructor shorthand *just forstdClass*
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-112112@lists.php.net to get a copy of this message
On 23 October 2020 21:14:49 BST, Mike Schinkel <mike@newclarity.net> wrote: >> On Oct 23, 2020, at 2:33 PM, Rowan Tommins <rowan.collins@gmail.com> >wrote: >> >> I don't follow; is the resulting JSON different if you cast to >object, or is there some other reason you prefer an object over using >an associative array directly? > >The by-reference semantics of objects vs arrays in PHP. *shrug* If you want things to be mutable between functions, stick an & in front of them; if you want copy-on-write performance, leave it to the engine. That doesn't seem to have anything to do with JSON or API as a use case. >That pattern can have a non-insignificant performance penalty when >dealing with a large number of objects, a use-case that is not >infrequent when processing JSON, especially responses returned via an >HTTP API. That gives us all the more reason to look for efficient ways of populating anonymous class instances, then. (And, indeed, populating actual named classes, if such a penalty applies to them too.) My point was that if we didn't already have it, making (object)$array create an instance of an anonymous class would feel natural and not lose anything that we have now. I see stdClass as a badly named and no longer necessary kludge, and would rather see features that help replace it than features that rely on it. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#112112) next »