|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-05-16 02:56 UTC] pravdin at vl dot ru
Description:
------------
Thanks for short arrays syntax! :) Now it's a time to create short object syntax for simple creatation of anonymous objects with custom fields. The current shortest way is:
$obj = (object)['field1' => 'value1', 'field2' => 'value2'];
Think it isn't beautiful :) I suggest the following syntax similar to JavaScript (which is very handly):
$obj = {{field1: 'value1', field2: 'value2'}};
or, if it possible, the same as JavaScript:
$obj = {field1: 'value1', field2: 'value2'};
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 03:00:01 2025 UTC |
Why would you need to store plain key => value pairs as objects? If you need extra functionality for your data, make use of your own or built-in classes. JavaScript has the object literal syntax because it distinguishses between an array - e.g. [1,2,3] - and an object literal - e.g. {name: 'Bob'}. PHP arrays can be used either way. This is why PHP has no such syntax.