Req #53266 [NEW]: Shorthand object initializer
From:
Operating system: Any (Windows 7)
PHP version: Irrelevant
Package: SPL related
Bug Type: Feature/Change Request
Bug description:Shorthand object initializer
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 bug report at http://bugs.php.net/bug.php?id=53266&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53266&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53266&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53266&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=53266&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53266&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=53266&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=53266&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=53266&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=53266&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=53266&r=support
Expected behavior: http://bugs.php.net/fix.php?id=53266&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=53266&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=53266&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=53266&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53266&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53266&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=53266&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=53266&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=53266&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=53266&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=53266&r=mysqlcfg
Thread (2 messages)
- dukeofgaming at gmail dot com