Req #81231 [Opn->Sus]: improve or add short method for creating objects, it was done with arrays.
| From: | requinix@php.net | Date: | Wed, 07 Jul 2021 20:01:00 +0000 |
| Subject: | Req #81231 [Opn->Sus]: improve or add short method for creating objects, it was done with arrays. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-234886@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81231&edit=1
ID: 81231
Updated by: requinix@php.net
Reported by: icarosnet at gmail dot com
Summary: improve or add short method for creating objects, it
was done with arrays.
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: Unknown/Other Function
+Package: Class/Object related
Operating System: Ubuntu 20.04
PHP Version: 8.1.0alpha2
Block user comment: N
Private report: N
New Comment:
Proposed and discussed a few times. But reconsider whether you really need so many stdClass objects
or whether some concrete types would be better.
Note that [] isn't a really shorthand: both array syntaxes look and work the same way, except
one starts with "[" and ends with "]" while the other starts with
"array(" and ends with ")". Meanwhile objects have no corresponding syntax at
all - long or short.
Perhaps that's because stdClass is a second-class citizen (pun intended) after arrays and
"real" classes. And while they're commonly used for comparisons, objects in
Javascript are more closely related to PHP's associative arrays; PHP's objects are closer
to traditional OOP classes, plus some added dynamic features.
Previous Comments:
------------------------------------------------------------------------
[2021-07-07 19:29:40] nospam at nospam dot com
But...why?
An object is an instance of a class. There are anonymous functions for closures. A request like this
should be discussed on internals, and has been discussed on internals in the past:
https://externals.io/message/106947
------------------------------------------------------------------------
[2021-07-07 19:23:34] fffr dot fffg at hf dot dd
what problem do you want to solve?
you don't need the () at all unless you want to provide parameters for a constructor - so you
save exactly one char for what benefit?
------------------------------------------------------------------------
[2021-07-07 19:13:29] icarosnet at gmail dot com
Description:
------------
improve or add short method for creating objects, it was done with arrays.
Test script:
---------------
The only two ways to create an object in PHP are:
$obj = new stdclass ();
$obj = (object) Array(); // the same as $ obj = (object)[];
or am I wrong?
why objects don't have a short initialization method:
$obj = Object(); // avoiding the use of new stdclass ();
$obj = {};
similar to how an array is created
$arr = Array();
$arr = [];
Actual result:
--------------
Error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81231&edit=1