Re: object literals
| From: | Richard Heyes | Date: | Fri, 01 May 2009 08:54:41 +0000 |
| Subject: | Re: object literals | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292173@lists.php.net to get a copy of this message | ||
Hi,
> $x = (object) array('a'=>1, 'b'=>3, ...);
>
> which works but isn't very lovely. it's neater in, for example, javascript.
Well, you could wrap it up in a function to make it a bit lovelier. Eg:
$foo = createObject(array('key' => 'value'));
It's not great, but PHP doesn't have a object literal syntax AFAIK.
--
Richard Heyes
HTML5 graphing: RGraph (www.rgraph.net)
PHP mail: RMail (www.phpguru.org/rmail)
PHP datagrid: RGrid (www.phpguru.org/rgrid)
PHP Template: RTemplate (www.phpguru.org/rtemplate)