Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116020 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59290 invoked from network); 8 Sep 2021 20:55:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Sep 2021 20:55:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B73331804C8 for ; Wed, 8 Sep 2021 14:33:42 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (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 14:33:42 -0700 (PDT) Received: by mail-qv1-f52.google.com with SMTP id 4so2447414qvp.3 for ; Wed, 08 Sep 2021 14:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=yUnQM76qs35rP+A21TldhDFzKH3ugPpX3Tr3Jl81waU=; b=mbwl8n1GKO3yPPhjfk4r6MdlmVStBCKw5eo1z0SZCfurrrDXKwQ4C5f81wChQH+LUt g/M1Fy8FIjL9IrG8P8kOGn/8XgRt+OkdROnsLpPFfiyC558oy8rt5oPMwXxhlFkPLjDI 1uchGMFCZq1nsP6D0DomSZFmCXMrNPYF8uTHfh1/QXN68NocIyRKmTI94aW4s84s48HC cqDdQ9IDfbQYcnFD6v12zJap1GHLR7wlY5usfvQBs+m1Ce7dD1G6uL1mQHEGAzuNVWVD gFy9vcHJo4Icc1gSXcMk1DIluh+1ftdvoxK3YSqdhGH6+mS+SMJjM8U5EbMac2c8DjJW SUuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=yUnQM76qs35rP+A21TldhDFzKH3ugPpX3Tr3Jl81waU=; b=LmSo40z9bveEY7k4yKG254O2BTKJcG+/KZ20zLhtqd/SO8f4ErpmOgoi5cwQCYYFxw JUHcUwaThlDjhHBMTXhnS3e1AiqLYzWkjOcRQGGql7y+2cqE4P7jTWBUHVIih+g7KJnJ SyBRSiogrzt8ugtgbs47bVjwsOtSKLPjJkEOapzoqSoOrf+BL2QRCt5M3S317NZwhtLl 8qjFaclIrknwzNOeO26B3ndtTHh5G2QtJWQDEPqA7hPFTAQbA4mB6Tmfe5nHmd9a921D xzXT2hQwHQgM4UQ/Z6eePQov+8nn0daOukm305Ro64hOHynmv3844HOUPzBM0u3NAoHt J15w== X-Gm-Message-State: AOAM530/4xqdBHqcdUJcRLFFfZcp7QzpB+QIKNrcyQ/Y6QUxlPJsez9K en0aMZlWjj9NEde3fJl3PlKOTg== X-Google-Smtp-Source: ABdhPJy41rOo4343HitmKI+icYJ/ydRyEcCy6IVHtzEgzKIOhMSNmS+MFAnk1Vctt4V4L0De7aILlg== X-Received: by 2002:a05:6214:122b:: with SMTP id p11mr384490qvv.25.1631136817843; Wed, 08 Sep 2021 14:33:37 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id o23sm174095qtq.7.2021.09.08.14.33.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Sep 2021 14:33:36 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) In-Reply-To: <0f084050-ede2-2c7a-90f0-26e17fe94836@gmail.com> Date: Wed, 8 Sep 2021 17:33:36 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <46f2e842-8608-0622-f1c1-3eb746658c84@gmail.com> <0f084050-ede2-2c7a-90f0-26e17fe94836@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] Alias stdClass to DynamicObject? From: mike@newclarity.net (Mike Schinkel) > On Sep 8, 2021, at 4:59 PM, Rowan Tommins = wrote: >> I assume we would also disallow dynamic properties in anonymous = classes too, right? After all, they are just statically declared classes = that the developer do not assign a name. >=20 > The difference I see is that stdClass/DynamicObject allows you to add = or remove properties from an object *after it has been created*. I think = a lot of use cases don't actually need that, and would benefit from = error messages when doing so accidentally. The concern is *not* were they are not needed, but instead where they = *are* needed. Such as when loading JSON from a source that does not = ensure the schema is 100% stable over time. That's also why I was hoping some of those complaining about deprecating = stdClass would explain explain their use-cases as they may know of = use-cases we are not considering. > You mentioned short-hand syntaxes like this: >=20 >> $obj =3D { >> foo: 1, >> bar: "hello", >> baz: true, >> }; >=20 > I would love for that, or some other short-hand, to be equivalent to = this: >=20 > $obj =3D new class(foo: 1, bar: "hello", baz: true) { > public $foo; > public $bar; > public $baz; > public function __construct($foo, $bar, $baz) { > $this->foo =3D $foo; > $this->bar =3D $bar; > $this->baz =3D $baz; > } > } >=20 > That is, an anonymous class, with exactly those three properties. If = you *also* want to be able to define extra properties after it's = created, you could opt into that using whatever mechanism a named class = would (parent class, trait, attribute, etc; see other thread). Exactly! Actually the same functionality for named classes is something I have = wanted since literally the very first day I starting using PHP so I = wouldn't have to run userland code that loops through an array that runs = for so many object instantiations. I have to believe it would be more = performant if in C. (Reasons I do that? Loading from JSON, XML and/or = SQL.). We've need either a magic method or ability to pass a close for = name translations and short circuiting. =20 That functionality is the primary reason I almost always use a base = class; it would be nice to get rid of that requirement.=20 > Similarly, the objects created by json_decode or PDO_FETCH_OBJECT only = need the *initial* properties to be dynamic, not to allow properties to = be added later. How do you define "initial?" -Mike