Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112123 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24042 invoked from network); 26 Oct 2020 15:06:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Oct 2020 15:06:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1C3F5180502 for ; Mon, 26 Oct 2020 07:24:54 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 ; Mon, 26 Oct 2020 07:24:53 -0700 (PDT) Received: by mail-wr1-f47.google.com with SMTP id j7so12780471wrt.9 for ; Mon, 26 Oct 2020 07:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=kpZIAMxCWYI6K/QxVYnoI7QUZ5oDFGn21puXfe88i/c=; b=mBIfw760tlUD8IWW3HepoU3JskLZl19vJdsWuYK+FWBjXZ8iDLcTJhG9Tfzw8ezRzk zdNF6BsRepe67dUz0UUG16zJ47H3WvEjXg4N2Y31urCcAkZLBapt9y4FLxlsMO8/PsbB Sw5tHlt8VYI0NJEwwm0fVQuAtHId5ULFv5N5qC78VFVUju1sB8O9BJigC+on4k1vQfR5 12iGZLeyZUO9yR/FfiSSJX09/Uu1n9hW1odeeL4Tp/EloVnU0GfmdaIr8tikq/KZywNF XXwfATzzGMY7Zw3XUAGtAoggDXIwCjUf7p5VzHddWRovdAk5kba9fcnNMkQHP010ujhc Wn1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=kpZIAMxCWYI6K/QxVYnoI7QUZ5oDFGn21puXfe88i/c=; b=SfwV1zLNxUkojRGYCcSi2SfdogFYDGbgnCk+JrVxXPsjbAumFZ21zt1Yzb5HgaEwa3 LlA4vj6faZctdVV7JTVs38v9YxPG8xJsScvjoKEYM3/D3RXqn6sId9mFQ6KElrA5HOJW 3KWePL4NaZ78sU19REOaVh0efMppNLpg+XaBijiSzjI3Kg77STTJ1NyX/8FN3xXVf4RL tyM1hYkjUH5D/i+5OzrvnnT+z3a5n9e4WFYkVMbYTZPJ/Jww8k2XQ/FcwctAILJUkX39 t1e04kIQySCemPz5W9js1N74C79MJAxRfYyhRX+puzOeWybyflzVa/oGAF+eThJKrimA rsyQ== X-Gm-Message-State: AOAM530u4+HjAvNC7DqDoEUYFk/zglimg4V/L7MjjLGkfHv8qfqotY2H O1EA75ndXenzrc0hzg42jtFhhr5ObFo= X-Google-Smtp-Source: ABdhPJxN6KNuZzf5WVBKz2x7MZR6aAJAr8Kls23VkWXQQA4S/xXUm3bITVFQeYmcz7fwC5FL845Nlw== X-Received: by 2002:a05:6000:12c2:: with SMTP id l2mr17963009wrx.76.1603722292075; Mon, 26 Oct 2020 07:24:52 -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 g144sm22215937wmg.30.2020.10.26.07.24.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Oct 2020 07:24:51 -0700 (PDT) To: internals@lists.php.net References: <5f92f1e0.1c69fb81.a800f.cbe1SMTPIN_ADDED_MISSING@mx.google.com> <2A808AB8-7179-41F6-88F4-A19C8F7FA171@newclarity.net> <02DD5C20-522B-46C7-B5EE-BC61E2EC4C6F@gmail.com> <5f9682b6.1c69fb81.10528.bc6fSMTPIN_ADDED_MISSING@mx.google.com> Message-ID: Date: Mon, 26 Oct 2020 14:24:48 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <5f9682b6.1c69fb81.10528.bc6fSMTPIN_ADDED_MISSING@mx.google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Is there any interest for object constructor shorthand *just forstdClass* From: rowan.collins@gmail.com (Rowan Tommins) On 26/10/2020 09:02, Andreas Bittner wrote: > With regards to the JSON looking different when casting to object: > > ``` > json_encode([1,2,3]); // result: [1,2,3] > json_encode((object)[1,2,3]); // result: {"0":1,"1":2,"2":3} > > json_encode([]); // result: [] > json_encode((object)[]); // result: {} Thanks, I hadn't thought of that. For cases as trivial as that, we have JSON_FORCE_OBJECT, but that's no use for creating structures like [{}, {}] > \stdClass is currently needed and widely used as no other structure > exists that offers dynamic property names while still being forcefully > JSON encoded as a JSON object. > We could replace this with another class. Maybe a real map > implementation. But without the replacement being present \stdClass > should be removed. Just to be clear, *any* object (except for a few with magic behaviour) can have dynamic property names added. As far as I know, defining "class stdClass {}" would be completely equivalent to what stdClass currently does (i.e. nothing). The only thing that makes stdClass at all special is the built-in functionality that returns it, notably the "object cast" short-hand for creating an instance and dynamically setting properties on it. The *functionality* (if not necessarily the *performance*) of that short-hand can definitely be replicated with any normal or anonymous class: https://3v4l.org/fGRBj > Do we already have a comprehensive list of features and use cases for > \stdClass? If not I would offer to compile one to the best of my > knowledge for a separate discussion on how to replace \stdClass if > possible and needed. I guess you could search the manual for built-in functions and operators that return stdClass instances. I doubt there are any that explicitly require them as input. For userland code, I'm not aware of any scenario where "new stdClass" could not be replaced by "new class {}", or why a polyfill would be any more than "if ( ! class_exists('stdClass') ) { class stdClass{} )". Regards, -- Rowan Tommins (né Collins) [IMSoP]