Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116006 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 79724 invoked from network); 8 Sep 2021 09:06:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Sep 2021 09:06:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1FE8A1804AD for ; Wed, 8 Sep 2021 02:44:14 -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.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 ; Wed, 8 Sep 2021 02:44:13 -0700 (PDT) Received: by mail-wr1-f41.google.com with SMTP id m9so2342698wrb.1 for ; Wed, 08 Sep 2021 02:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=a7iTSCLn834u/sA1xrqQdpxjkDaUbfnbXGcpoFojME4=; b=O/WPFbfzYmIZweVHpWyJ+NyIq9WWFoCbGPIGr0MX8QA5szO74pPs0lduH7nS7LtZSB GWBSQHHesaVrlX6kGRo+7o0D3oS5GyUP/Ic3ph72YX5z5sIOJNesVolnZlBIycvHibsI e4hTYIC//q5SD9MnryhDGql1WuvZB0vnzb1WxC2O2e/Hm1fghLSNcoiYMLdlJtVIsseV xJLL/R8s5DpqEX5Ohg9J1RQKBcurcIyYclzvENINTKTzk5NRjOc3iD4fmSh4VC/z7fDv UH/DsiekTu50MusWLBzvjsB1cuL3gIZy//U/FA3CVTRJkUuzQoY6v2po6etHriHaX7wE Q0pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=a7iTSCLn834u/sA1xrqQdpxjkDaUbfnbXGcpoFojME4=; b=vwUDV85fLSRpq4V3NZkh11VgwNbbd0d0wbb3pDQeN9GAwHy4niZ2/CjD45djsbj69R 9lEG+J+lhd+0MN58I9Z0dyDQd53wnZ8Hjvzkz+3ojU//cAQh/Lm+Tfw+3UNs7TRzNTfK trvQcjk0uwpXxkofS/B9hnAF5QZZI1fN/wY2CpcLwoqhuq8UeXM689WDZgzimXpUK3S7 HtUkaiX638goxamqKHygK+EeiwhK4oAUb7WRr8uj0So0gqhs1kHoDe3K872dSpwcbZlz BEMp1QF31sU4NBCtzvIS90RsksY2Zl5F7gQu+SLxxniCEtJ1O9POvrFCawAz8VyY52vJ 02dg== X-Gm-Message-State: AOAM533k6zV5OsDkH1g3iOhpvpCd2pXsCh9AtOrf3Wlclgt09Nla4/lk YdlVPpR6Zp5HxOYE7INy5NyWrLtw7GA= X-Google-Smtp-Source: ABdhPJyVCZdg8iehmuMvJTflETRv7m6U6cg88P2ozzjqz1lCAfNnNZD66Qy6/Z+vavU1O9NLSrRh2w== X-Received: by 2002:a5d:4dce:: with SMTP id f14mr2962344wru.204.1631094250236; Wed, 08 Sep 2021 02:44:10 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id g1sm1879752wmk.2.2021.09.08.02.44.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Sep 2021 02:44:09 -0700 (PDT) To: internals@lists.php.net References: Message-ID: <46f2e842-8608-0622-f1c1-3eb746658c84@gmail.com> Date: Wed, 8 Sep 2021 10:44:08 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] Alias stdClass to DynamicObject? From: rowan.collins@gmail.com (Rowan Tommins) On 08/09/2021 09:45, Mike Schinkel wrote: > So I am trying to get around what this would actually mean in practice, and what the ramifications would be. The proposal is that the new name is an "alias" - the same class, but with two names. So the following would all create exactly the same object: $obj = new stdClass; $obj = new DynamicObject; $obj = (object)[]; The following would be true for all of them: assert( $obj instanceOf stdClass ); assert( $obj instanceOf DynamicObject ); There are some places that have to return some "real" name for the class, like get_class($obj). The current proposal is that "stdClass" be kept as the real name, at least initially, so you would see this: $obj = new DynamicObject; echo get_class($obj); // stdClass > So while trying to get my head around the ramifications I prepared > this bit of introspection, which is still missing some applicable > tests I am sure: > > https://3v4l.org/MDlOn#v8.0.10 You can get a better idea of what's being proposed using the class_alias() function, which lets you create an alias for a user-defined class: https://3v4l.org/a4EI0#v8.0.10 > Is it just a special-cases that will cause as much confusion for developers trying to understand why there are too names for the same thing as it will help those who will better understand the new name That is certainly a risk, and a factor in favour of having some plan to retire the old name, even if only after a long overlap. > or is it more fully addressing the use-case for why people use dynamic objects? The thread comes from a comment I made in Nikita's discussion about deprecating dynamic properties on normal objects. There was no grand vision behind it, just a long-standing dislike of the name "stdClass", and a concern that documenting "extends stdClass" as a way to enable dynamic properties on a custom class would make the confusion worse. > So what are the use-cases where dynamic objects still make sense, and just as importantly what about those use-cases is still suboptimal besides just the class name? To be honest, I think most uses of stdClass would be better served by anonymous classes, and would have been written that way if the feature had existed for longer. The one thing missing from anonymous classes right now is an elegant way to capture data from outer scope when you create them. Regards, -- Rowan Tommins [IMSoP]