|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53266 Shorthand object initializer
Submitted: 2010-11-08 19:28 UTC Modified: 2010-11-09 04:31 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dukeofgaming at gmail dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: Irrelevant OS: Any (Windows 7)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
48 + 35 = ?
Subscribe to this entry?

 [2010-11-08 19:28 UTC] dukeofgaming at gmail dot com

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(

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(

Following the same rule than array to object casting:

return object(

"5" would be ignored since its key would be numeric.




Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-09 04:31 UTC]
-Status: Open +Status: Wont fix -Package: SPL related +Package: Scripting Engine problem
 [2010-11-09 04:31 UTC]
Given the short syntax for arrays RFC failed, I don't see much hope of this getting up. Nevertheless, writing an RFC ( and sending it to the internals mailing list would be the right way to propose this.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jun 20 08:01:24 2021 UTC