Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116747 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53865 invoked from network); 31 Dec 2021 06:13:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Dec 2021 06:13:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A9F761804C4 for ; Thu, 30 Dec 2021 23:19:59 -0800 (PST) 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,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS1836 195.49.0.0/17 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (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 ; Thu, 30 Dec 2021 23:19:58 -0800 (PST) Received: from smtpclient.apple (unknown [88.230.52.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id D7083151668F for ; Fri, 31 Dec 2021 08:19:55 +0100 (CET) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) X-Priority: 3 (Normal) In-Reply-To: <1640910093.890171965@f721.i.mail.ru> Date: Fri, 31 Dec 2021 10:19:54 +0300 Content-Transfer-Encoding: quoted-printable Message-ID: References: <1640910093.890171965@f721.i.mail.ru> To: internals X-Mailer: Apple Mail (2.3693.40.0.1.81) Subject: Re: [PHP-DEV] RFC: Stop to automatically cast numeric-string to int when using them as array-key From: cschneid@cschneid.com (Christian Schneider) Am 31.12.2021 um 03:21 schrieb Kirill Nesmeyanov : > I support this behavior fix because in its current form, due to a = similar problem (almost?), all PSR-7 implementations contain bugs that = violate RFC7230 (section 3.2: = https://datatracker.ietf.org/doc/html/rfc7230#section-3.2 ). Thus, = physically, by the standard, all headers can have the name "0" (like = =C2=AB0: value=C2=BB), but when stored inside implementations, it is = converted to a string and a problem arises ($message->getHeaders() // = returns array instead of array). >=20 > To solve this problem without BC, it seems to me that Nikita's idea = with =C2=ABdeclares=C2=BB is most suitable, like: > ``` > declare(strict_types=3D1, strict_array_keys=3D1); > =20 > $array["0"] =3D 42; // array(1) { string(1) "0" =3D> int(42) } > ``` I probably sound like a broken record but I'd strongly advise against it = as it creates language dialects which means a line like $a["0"] =3D 42; behaves differently depending on context, e.g. copying code from = Stackoverflow might lead to subtle bugs and reminds me way too much of = the ini-settings magic_quotes_gpc. My take is that changing behavior is ok if it can go through a = deprecation/warning phase but that is IMHO not the case here. If people want to have different behavior I'd rather have a new type = like $a =3D new Dict; $a["0"] =3D 42; possibly with a short-hand for initialization. Regards, - Chris