Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125960 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 7791A1A00BD for ; Thu, 14 Nov 2024 21:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1731619814; bh=zq1bAsbodTlBSFTHnSkPVHF8f/y4g/zm5lgWRkoUU5w=; h=Date:To:From:Cc:Subject:In-Reply-To:References:From; b=P1s+jPFfSgdEFv8OwBU0Cy7AVovFBMzpFK1BDnTS4XxK9bgKb4zbvpMs1DnZXtVXJ Y+vDGuJ3sVrL0bS8LjW7Iu3GYbSiM5bvwp73Qb8lgrYQy8bNgb1G0zlCf/9o4qcUxZ jwK+OBXTp53XSfjksLjQoD9JY2aS13CISLWAcuuN+IBopi9TIiOrdB6jWzfYVf3FuP 8Oanz1xc3tgOJvqV6aQG520NUImzmABWvY6rYdnYvw/NNc8I54WPM5x4TdngiIx0Tf yBjsVtKoFvr2+E1VwGS/oHcIVtTJlX+aDE90akiVWXBwtXP59QjIgfYJuQDO03Jado ajIf0xk8naVhw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2113218006D for ; Thu, 14 Nov 2024 21:30:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-4018.proton.ch (mail-4018.proton.ch [185.70.40.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 14 Nov 2024 21:30:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpb.moe; s=protonmail2; t=1731619654; x=1731878854; bh=zq1bAsbodTlBSFTHnSkPVHF8f/y4g/zm5lgWRkoUU5w=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=Gfz1ir7EKrtcHW9m8p4QF36DkhWSSzMUtm5/3fVTL214gGcMKzlt0o3SsOYrMuZBN 5fcp72opDdVC4l1xaBW8nIqcj4Mw7+x8ru1745S3/g2/OWXW5W1tt5/IEjeV9GBYRL ZbqmW62HvdN7sa+b7zlcmTPP+fTxjUnclsW480Hdix7fOAUTapDp1fixP6ckDm/YcV Ma4C17e+//AG1cRM+exY98VF+pZtK6dnWuq5YjdvIzWTCADqtrDsu+Q2D6Xyu07ZTm 72Jm8/+6wEkbwW8sHQWA4rNZJrjG6x3w6Pu4VwXmt2JTqH3t2Rdg5KdHsAVUK/7ioY kaEPOziOLbmWw== Date: Thu, 14 Nov 2024 21:27:30 +0000 To: Larry Garfield Cc: php internals Subject: Re: [PHP-DEV] [Discussion] Make objects unpackable by default Message-ID: In-Reply-To: <3dcc5393-6ce7-465c-abe6-ecb687b0f369@app.fastmail.com> References: <3dcc5393-6ce7-465c-abe6-ecb687b0f369@app.fastmail.com> Feedback-ID: 96993444:user:proton X-Pm-Message-ID: b2341c391770c4333f287b6c2fe2912397e07ba6 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: internals@gpb.moe ("Gina P. Banyard") On Thursday, 14 November 2024 at 17:24, Larry Garfield wrote: > On Thu, Nov 14, 2024, at 7:37 AM, Christian Schneider wrote: >=20 > > Am 14.11.2024 um 10:59 schrieb Marco Pivetta ocramius@gmail.com: > >=20 > > > On Thu, 14 Nov 2024, 11:29 MrMeshok, ilyaorlov124@gmail.com wrote: > > >=20 > > > > Hello, Internals! > > > >=20 > > > > As you know if you try to unpack a regular object (`...$object`) yo= u will get an error: Only arrays and Traversables can be unpacked. > > > > I don't really see a reason for this restriction, because foreach o= n objects works perfectly fine, so I made a feature request on GitHub to ch= ange this behavior (https://github.com/php/php-src/issues/16038) and was ad= vised to see opinions on this here. > > > > So, what do you think? And does this change require RFC? > > >=20 > > > TBH, foreach on objects is already quite an abomination in itself = =F0=9F=98=AC > >=20 > > It is a bit less weird if you use value objects or json data in object = form. > > I would be careful to judge how other people use the language, just say= ing ;-) > >=20 > > - Chris >=20 >=20 > Judging how one should use a language is a core component of language des= ign. >=20 > I'm with Marco on this one, and I'd be more than happy to get rid of fore= ach($object), too. It's way, way more complicated a topic than you think. >=20 > How does visibility play into it? > Should hooks be invoked or no? > Do references play into anything? >=20 > Those are some of the questions we had to deal with for hooks and foreach= (). It's non-trivial. You'd need to address all the same edgy issues here, = too. >=20 > And that's assuming it's even a good idea, which I don't think it is. If = you are using a value object to define unordered arguments, just pass the v= alue object itself. If the receiving function can't handle that, then it is= simple enough that you don't need a value object. If that's not the case, = then your code design is bad and the language should not try to paper over = that for you. Either simplify the function or adapt it to use a value objec= t directly. (With union types you can even do so in a BC fashion much of th= e time.) Agreed, this bites us constantly when needing to reason about what an "obje= ct" is in PHP. Similar to array it mixes the concept of a struct, with that of a reference= value, and "overloading" various behaviours (e.g. iterators and ArrayAcces= s). It is *extremely* simple to go from foreach ($object as $prop) {} to forear= ch(get_object_vars($object) as $prop) {} and mandating this would resolve a lot of complexity, be that from the pers= pective of what is "possible" or not to do, and from an engine PoV. Best regards, Gina P. Banyard