Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117458 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62343 invoked from network); 30 Mar 2022 12:58:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Mar 2022 12:58:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B449B180540 for ; Wed, 30 Mar 2022 07:27:12 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (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, 30 Mar 2022 07:27:12 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 448FC32015ED for ; Wed, 30 Mar 2022 10:27:11 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Wed, 30 Mar 2022 10:27:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=6m2SkGfPzeIzxdoxkD/Uokr/gG7Pao8b1WrpEy3kB38=; b=iNe1yHFW Uqg9IPnef5WyNUXQt8iKSAFVDATLOA+yjD9EjEzWpNXnTSv8WXLuxgpzo73KD6I1 3uyGZubSi0OxTuKn5ybqQM+7ZYLtktDoOFvzVzYY+u8knFyOVBCsaSZ1aUqSIMyZ fgYbiVOwdq/1vcw7uoFjUIopppaoFpHWI0RD7zbFxMA++K9oSdlAmY04iKYuLkJC b3LbaedCgcJwHgpq3T3E1iDIuXvlDlqj8LlrFQK6Ik26Aj9DNrOoRggCYkN7mjuo 8p2M1w+raWbEUMao2XvcvWTIkElSsnvvHAbit9TeYQfsUdQmCf0akIjvvPqy4SEb CEfqyA+v5UaScw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeivddgjeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7CD1CAC0E98; Wed, 30 Mar 2022 10:27:10 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4911-g925b585eab-fm-20220323.003-g925b585e Mime-Version: 1.0 Message-ID: <486f1c99-aaef-43aa-b8a8-c9dcbc68ec8d@www.fastmail.com> In-Reply-To: <14179C1D-F64A-4B01-9A1F-274730748095@gmail.com> References: <9ecce8c9-c8bc-93e3-25f0-386c2c41ca1a@gmail.com> <14179C1D-F64A-4B01-9A1F-274730748095@gmail.com> Date: Wed, 30 Mar 2022 09:26:50 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Undefined variables and the array append operator From: larry@garfieldtech.com ("Larry Garfield") On Wed, Mar 30, 2022, at 9:11 AM, Claude Pache wrote: >> Le 29 mars 2022 =C3=A0 21:44, Rowan Tommins = a =C3=A9crit : >>=20 >> Hi all, >>=20 >> If $foo is not defined, statements such as $foo +=3D 1 and $foo .=3D = 'blah' raise "undefined variable" Warnings in PHP 8, and will throw Erro= rs in PHP 9. However, the very similar looking $foo[] =3D 1 succeeds sil= ently. >>=20 >> This seems odd to me, as "append to string" and "append to array" see= m like very similar operations, with most of the same use cases and poss= ible bugs. >>=20 >>=20 > > > Hi, > > There are various subcases to consider: > > (1) $x[] =3D 42; and $x['y'] =3D 42; where $x is undefined > > (2) $x[] =3D 42; and $x['y'] =3D 42; where $x is null > > (3) $x['y'][] =3D 42; and $x['y']['w'] =3D 42; where $x is an array,= and=20 > $x['y'] is undefined. > > Of course, I agree that (1) should be an error. > > The case (3) is similar to (1), but I think it is more controversial t= o=20 > change. I bet that they are various places in my code that take=20 > advantage of that feature, although personally I don=E2=80=99t mind to= write=20 > $x['y'] ??=3D [ ]; when needed. We should probably also consider if there are other places where we're c= omfortable with ??=3D working correctly. I'm not sure off hand if it sh= ould be acceptable in 1 or 2, but it's a question we should think throug= h and document decisions on. --Larry Garfield