Req #53266 [Opn->Wfx]: Shorthand object initializer
| From: | aharvey@php.net | Date: | Tue, 09 Nov 2010 03:31:13 +0000 |
| Subject: | Req #53266 [Opn->Wfx]: Shorthand object initializer | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-155871@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53266&edit=1
ID: 53266
Updated by: aharvey@php.net
Reported by: dukeofgaming at gmail dot com
Summary: Shorthand object initializer
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: SPL related
+Package: Scripting Engine problem
Operating System: Any (Windows 7)
PHP Version: Irrelevant
Block user comment: N
New Comment:
Given the short syntax for arrays RFC failed, I don't see much hope of
this getting up. Nevertheless, writing an RFC (http://wiki.php.net/rfc)
and sending it to the internals mailing list would be the right way to
propose this.
Previous Comments:
------------------------------------------------------------------------
[2010-11-08 19:28:00] dukeofgaming at gmail dot com
Description:
------------
Hi,
To often I've been in the situation where I prefer to use an object
rather than
an associative array to manage data, and in order to keep my code clean,
I
prefer to do this:
return (object)array(
'one'=>1,
'two'=>2,
'three'=>3,
'four'=>4,
);
Rather than this:
$data = new stdClass();
$data->one = 1;
$data->two = 2;
$data->three = 3;
$data->four = 4;
return $data;
AFAIK, arrays and objects are similar internally, so why not allow
this:
return object(
'one'=>1,
'two'=>2,
'three'=>3,
'four'=>4,
);
Following the same rule than array to object casting:
return object(
'one'=>1,
'two'=>2,
'three'=>3,
'four'=>4,
5
);
"5" would be ignored since its key would be numeric.
Regards,
David
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53266&edit=1