Edit report at http://bugs.php.net/bug.php?id=53266&edit=1

 ID:                 53266
 Updated by:         [email protected]
 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

Reply via email to