Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115996 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 17543 invoked from network); 7 Sep 2021 15:37:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Sep 2021 15:37:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C5EF2180540 for ; Tue, 7 Sep 2021 09:15:19 -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.7 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS35329 80.237.132.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wp160.webpack.hosteurope.de (wp160.webpack.hosteurope.de [80.237.132.167]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 7 Sep 2021 09:15:18 -0700 (PDT) Received: from [2a02:8109:9d40:1d44:33cb:68aa:d989:6e10]; authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1mNdki-0008W9-QW; Tue, 07 Sep 2021 18:15:16 +0200 To: internals@lists.php.net References: Message-ID: Date: Tue, 7 Sep 2021 18:15:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-bounce-key: webpack.hosteurope.de;marc@mabe.berlin;1631031319;46d01d69; X-HE-SMSGID: 1mNdki-0008W9-QW Subject: Re: [PHP-DEV] Alias stdClass to DynamicObject? From: marc@mabe.berlin (Marc Bennewitz) On 06.09.21 17:28, Nikita Popov wrote: > Hi internals, > > In the thread for deprecation of dynamic properties, Rowan suggested that > we alias "stdClass" to "DynamicObject" in > https://externals.io/message/115800#115802. I wanted to split this > discussion off into a separate thread, as this can be decided independently. > > The rationale for this is that "stdClass" is something of a misnomer: The > name makes it sound like this is a common base class, as used in a number > of other languages. However, PHP does not have a common base class. The > only way in which "stdClass" is "standard" is that it is the return type of > casting an array to (object). > > The actual role of stdClass is to serve as a container for dynamic > properties, thus the suggested DynamicObject name. > > What do people think about adding such an alias? Is this worthwhile? I do like the idea very much as "stdClass" is most confusion and also wrong. The name "DynamicObject" is much better but I'm not sure if this is a good name either. * It's a class -> Why do we suffix it with "Object"? * Yes it's about dynamic properties - but is this the user goal to have dynamic properties or is it an implementation detail to get something else (map/dict)? Wouldn't it be better to name it for what purpose it's being used (map/dict/ordered dict/...) instead of how this is done? And if we want to go that route we could also add common functionalities to it like getting list of keys/values converting to array iterating etc. it's already possible right know by casting to array but it would be more logically. Yes we have assoc arrays in PHP to serve the purpose but this also has it's downsides as there is no type for it and the issue of converting an empty array from/to JSON (is it a list or a map?). The big difference, of course, is the by-ref vs. by-value. Hope that's not stupid questions? Greetings, Marc