Re: Proposal: shorthand object property setting syntax.

From: Date: Sun, 28 Mar 2010 01:14:36 +0000
Subject: Re: Proposal: shorthand object property setting syntax.
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-47666@lists.php.net to get a copy of this message
On Mar 27, 2010, at 3:59 PM, Bharat Nagwani wrote: > I might have missed earlier emails. How about this? > > $myLongNameObject = new myLongNameObject { > property1: '11111', > property2: '22222', > property3: '33333', > property4: '44444', > property5: '55555', > }; > > Can we avoid the new as well like in Javascript? > > $myLongNameObject = { > property3: 'xyz', > property4: 'abc', > property5: 5, > property6: { > a: 1 > } > }; Except that "new myLongNameObject" and { } are not the same, your latter syntax — just as in JavaScript — would yield an anonymous object, essentially the same as "new stdClass" :) You could just as easily do: $myLongNameObject = (object) array ( 'property3' => 'xyz', 'property4' => 'abc', 'property5' => (object) array ( 'a' => 1 ) );

« previous php.internals (#47666) next »