Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112084 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88130 invoked from network); 21 Oct 2020 00:14:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Oct 2020 00:14:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BB6B81804C3 for ; Tue, 20 Oct 2020 16:31:04 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 20 Oct 2020 16:31:04 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 0AA2F5D8 for ; Tue, 20 Oct 2020 19:31:02 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Tue, 20 Oct 2020 19:31:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=5HAYT0 Ou0524/PJziQEJMD437y9f6LEGo6MVBKsaDoU=; b=LVV15OG83Is5ffZbpfw951 BVDCJhDOcNAUt/9EfTVYD/21sLIuWBqXbAAYYT/uidnrYFdwtA8ErxkdSJ7VeART 0/YFYKoUOOClJfefjsXbtuDYXNM9yW2S/oAHQupuUQxZms4p4bE75UyBDRNLdZ4K OB4GU7ZksnwW47vfH5ssuE2cUU2aNu2dCEHghL1bssulPVFRNk/5OQqqdXnrZGLt xj55MKWHuJOOXqNQ/e5Cz/mmydHbjcrEKhKJOAVEBHhOdxT6i3DuHnjkoyUme/1d x+TeTdqvc+O1FHT/wyAAViVbWPSuQ2qYyJk+QdDOgYrl5ag0/H0rbQE5UvRTWCUA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrjeeggddvudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderreejnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepveduudeiudelheehuefgvedtteejuedtveeihfdutdet tefgveetkeduhfelgffgnecuffhomhgrihhnpegvgihtvghrnhgrlhhsrdhiohdpphhhph drnhgvthenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 380E014200A2; Tue, 20 Oct 2020 19:31:02 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-502-gfef6c88-fm-20201019.001-gfef6c888 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Tue, 20 Oct 2020 18:30:41 -0500 To: "php internals" Content-Type: text/plain Subject: =?UTF-8?Q?Re:_[PHP-DEV]_Is_there_any_interest_for_object_constructor_sho?= =?UTF-8?Q?rthand_*just_for_stdClass*?= From: larry@garfieldtech.com ("Larry Garfield") On Tue, Oct 20, 2020, at 5:53 PM, tyson andre wrote: > Hi internals, > > e.g. `$x = object{key: object{'escaped-literal': $v2 }};` > (equivalent to `$x = (object)['key' => (object)['escaped-literal' => $v2]];`) > > For example, in JS, non-string key literals are surrounded in `[]` to > unambiguously reference them. > Here, that could be `object{[$key]: $value, [MY_CONST]: $other}` - but > `(MY_CONST)` would also work > > - https://externals.io/message/52990 was mentioned 9 years ago but > would potentially conflict with future block expression RFCs > - `object{key: $value}` is suggested here for similarity to named > arguments > > Benefits: > - Shorter and more readable code - casting an array to an object is an > unintuitive and potentially hard to remember > way to create an object literal > - Make it easier for users to use objects for generic associative data > instead of using arrays both for lists and associative data, > in situations where it may result in more usable APIs > > For example, > > ``` > $x = new stdClass{}; > $x->prop = new stdClass{}; > $x->prop->a = $a; > $x->prop->b = $b; > // Could be shortened to > $x = object{prop: object{a: $a, b: $b}} > // $x = (object)['prop' => (object)['a' => $a, 'b' => $b]] > ``` > > This proposal is only for stdClass - there was not much interest in > https://wiki.php.net/rfc/compact-object-property-assignment > and the combination of named properties and constructor property > promotion helps with the readability of other classes. > > Thanks, > - Tyson The only data structure worse than an associative array -- from the point of view of performance, self-documentation, or usability -- is stdClass. :-) I can't recall using it in the last decade at least, and my code has been better for it. Especially now with constructor promotion and named properties, I'd prefer to just forget that stdClass exists and encourage others to do so as well. --Larry Garfield