Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116160 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42346 invoked from network); 25 Sep 2021 15:18:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Sep 2021 15:18:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1A0E41804E1 for ; Sat, 25 Sep 2021 09:00:02 -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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_HOTMAIL_RCVD2, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.80.0.0/12 X-Spam-Virus: No X-Envelope-From: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2019.outbound.protection.outlook.com [40.92.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 25 Sep 2021 09:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cEOJGtGFFZVD+988ncYTKB1DbvH6T8YFXDq2QHPCNMOLMfAuyhYkMEw0pVjtCIsVyj6z0pzpyP6Ge60b2/r9HaWOyVFxho0ExgPOXLRgOFyEdb72cM6wM6SO4MCk80XF45TBS1Tj8rQOMIBstaRsrFn2pASkLd2q5xok34DeSv8J1GCFDaLrMfMSgAEtZi6MyYxMBKao/lVw+ZuR5dNo8mlFtMZO887BNHdXI9XyvOejJHthRtCKrQG2CNuBOCinIE0QF/GkEIfHIOJJGbuvtV5CIf+odsIDNsWf4I3/CTvtjuTOCCVWNpl2OwI5dFiJSX5FGWLBU+TXLlSm5Xxm+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=H25l+HvW44llY/cSE5eCJwuKpCYyHh6JFCZsrqCxYoM=; b=NwpValMeM3t/alYDj6jpaZnIqkLk0EqhrASE1LzhNntD06FzcJRnoWugd6a/zi7JFNwcxG9KTsWUZzbb/mIgcBq5BmtEVQmpJmAPgbBr+aw4Y/QOx9ipro++i63We93k/pJdisNytjX/VJjlEUfNsbVmkIEr3lzgzZ2pmp1d+li6bzffVlz1oUKjWkgMsGm72o7vQmapptFekT/m/E5sdmD6LN6+m592M5OBepwfJqAm+BHtwQ1WV/2qnKvGbUXHAN82gTXfdSuSN5jINRM4N7UfLw4LZGw6RgJhdQQtnttfCcw4ibghfDh7d8D9Rd15wsmvBHGrVUA1m2+wfN5r+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H25l+HvW44llY/cSE5eCJwuKpCYyHh6JFCZsrqCxYoM=; b=gJ9LktUl4ncwmSsWVnGSvYUpwJzeNoDPe+T6xIzmeyZCZ710w70lIK9FP8Jy24HEoYzIPmFegn/tm1ehuw+J1T8FEz+HeuIxW/JfYombBbiHZ4qcP6+BlYj0L1nHPmbTOB/NHsS9aHF/mO70IjDPOmzKay4IkB/wpu8aHTMus9w5vhz8f6w8wIVkdu228mTK0w8U8kCxkfsgegx61ocUO0u2XWW2+cWDZggE+rgp/htSj4nmiXXqxn6NLH9tu10szAELGBACPCrLBji8HizXYT6lSDOLSq/VRSHH6XNftPilmCC3gjsgzIp7rGo2aNW+BwVOmAbvXax2ZNNfLCxAyg== Received: from DM5PR17MB1481.namprd17.prod.outlook.com (2603:10b6:3:147::17) by DM6PR17MB3163.namprd17.prod.outlook.com (2603:10b6:5:192::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Sat, 25 Sep 2021 16:00:00 +0000 Received: from DM5PR17MB1481.namprd17.prod.outlook.com ([fe80::e832:bd41:4114:64d2]) by DM5PR17MB1481.namprd17.prod.outlook.com ([fe80::e832:bd41:4114:64d2%11]) with mapi id 15.20.4544.020; Sat, 25 Sep 2021 16:00:00 +0000 To: "internals@lists.php.net" Thread-Topic: [PHP-DEV] Allowing `(object)['key' => 'value']` in initializers? Thread-Index: AQHXsiErO0Vz7k4CHEy3AX0ZJcoPi6u05TYAgAACQZ4= Date: Sat, 25 Sep 2021 16:00:00 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: 1ac4474b-9dcc-9296-8b5b-d21dcf66342b x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [93Su6DAPcDL5CEA+o1WGSN9yYeqNAzkdMStHD6bcgduV8CRsv2gqtwTXN7RaW5LKRqbPbntxAfg=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1c14d447-3a1d-44c6-ed19-08d9803d8767 x-ms-traffictypediagnostic: DM6PR17MB3163: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ayCPiJSmXyWEb+WdPd5h2VHJUusU9376VLFC9sWMiP9oKa7J3qJcXi/ktWCYUjJdOlkY7VEcpi12mGfKM5NRN7eLQfQ00RaIJIjXNlQkZxMMhFl3EMfh0bhfa9RssksO7+Igdr1YToOETbclaERIkPXTFoYaEbzDkTBJVEIC3qwmB3iZkgHBTUvgnUugOrkzXYysTiqxPr4HnIU0decZV6aw1Q5NzyBAkMoaWOtED2Ss/bQtyMjGCs/OuqX5nW1GPEglK1EQyJRHweCb3z6c10lzKODXf36e9xbXJ4wGCsHjUxP2II/CuRkaSyBcFey5rBYyqVJgZZf8fyvW1S67rYwtrudFOHbzXZb0vCVDUupPw524LL0/7dEfVky62ss9NaRPkYkXdmWg/a/vuzMeeb7x+ySLzWLiKlL2kUovr632JuZ8Tb1ie1ucpzdvoIB7SYQMiwyOiYnJCv20n+uyE39x6lbQh70SqhQHgsRBaC4whqeMshHJSXYl6CASws8e1ocuaEMScNPGBzA5a/QA6A== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: 6irzNzUcJvbrL4pTNi6fd/d48HsZaIAisQFtdaUlis7Kb9ZuUNJFSZbqABDc5gi83FMFUYzwK1QgXBtoAQeDP3ekx00GnaEVrK27VoBh+1kpdRf359JzX9vZoJ9+9KEhFMWSANB3k713JaNgLWMV3gPa1NcVHWsRQb5bigIvpDqciTDI0PhWgDcQFYHFp4eJklKmXIgLqIvnmd+CW/9p0A== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-21df5.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM5PR17MB1481.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 1c14d447-3a1d-44c6-ed19-08d9803d8767 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Sep 2021 16:00:00.2091 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR17MB3163 Subject: Re: [PHP-DEV] Allowing `(object)['key' => 'value']` in initializers? From: tysonandre775@hotmail.com (tyson andre) Hey Marco Pivetta,=0A= =0A= > > What are your thoughts on allowing the `(object)` cast in initializer t= ypes where `new` was already allowed, but only when followed by an array li= teral node. (e.g. continue to forbid `(object)SOME_CONSTANT`) (see https://= wiki.php.net/rfc/new_in_initializers)=0A= > > ...=0A= > > Reasons:=0A= > > - The ability to construct empty stdClass instances but not non-empty o= nes is something users would find surprising,=0A= > > and a lack of support for `(object)[]` be even more inconsistent if f= actory methods were allowed in the future.=0A= > > - stdClass is useful for some developers, e.g. in unit tests, when usin= g libraries requiring it for parameters,=0A= > > when you need to ensure data is encoded as a JSON `{}` rather than `[= ]`, etc.=0A= > > - It would help developers write a clearer api contract for methods,=0A= > > e.g. `function setData(stdClass $default =3D (object)['key' =3D> 'val= ue'])`=0A= > > is clearer than `function setData(?stdClass $default =3D null) { $def= ault ??=3D (object)['key' =3D> 'value']; `=0A= > > - stdClass may be the only efficient built-in way to represent objects = with arbitrary names if RFCs such as https://externals.io/message/115800 pa= ssed=0A= =0A= > =A0 passed=0A= >=0A= > Right now, there's even an interest in getting rid (or deprecating) dynam= ic properties on objects: why push the complete opposite ways?=0A= > =0A= > What is the actual value of using an stdClass instance instead of an `arr= ay` (already supported)?=0A= =0A= My original message had a section with reasons why an end user might want t= hat.=0A= =0A= There's a push for getting rid of (or deprecating) dynamic properties on **= objects that are not stdClass (or subclasses)**=0A= Not a push for getting rid of stdClass. Way too many things use stdClass to= get rid of stdClass.=0A= (whether or not stdClass gets aliased or even renamed to DynamicObject).=0A= =0A= ```=0A= php > var_dump(json_decode('{}'));=0A= object(stdClass)#1 (0) {=0A= }=0A= ```=0A= =0A= Thanks,=0A= Tyson=