Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116825 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25944 invoked from network); 6 Jan 2022 06:22:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2022 06:22:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 63B451804E3 for ; Wed, 5 Jan 2022 23:30:13 -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.3 required=5.0 tests=BAYES_50, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS 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-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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, 5 Jan 2022 23:30:12 -0800 (PST) Received: by mail-ed1-f44.google.com with SMTP id 30so4530715edv.3 for ; Wed, 05 Jan 2022 23:30:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=Dy3Nqw29QBFd3NrVb8i+q47Nmqm4Xy5XocwUbTw91GQ=; b=YNYHUyMQo7UfdzJhX4oy+zsdm9J8VdQC18jr3lnFDtk/aV0DrN3zskbqrMeoC7s/Lp BToCYSdIuLx8sGxJvEnKYgI4PnSrPP/is95q6xnvFQsGt0JUYQcttIjyDSulqO2OUp1U C7eNBD2rrvLNFUPMISakzejozVHJ6vpjgjFMiEbVAsKPJooAWzBFNCqcXZSuHUG8rTVX kVJQZuk9uK1oPlGH3b4xYdfUmCZAIwQAtIN1vdKFqJOgjPSxzZbofHxxlp0wqDwj/omk hJP85Khk7XUz0Vjcp+8sOhm973NVe9XOUd9b8z7/r2APc7Xwh/bBDlkavbq5+NpSinLy Ygww== X-Gm-Message-State: AOAM530RtcG1XGwBay6LRjDkOr9vBkbdyYCEsPRnslXMVfyJfaUkaXgH eqftrX0unc9NrKxMTm9yiJeAji2Uw4DG92l3 X-Google-Smtp-Source: ABdhPJynkS2qJEDzaPmCTvwhponUGK/tEx+tFd3RNwXP0+Vl5pyyTZeoZa243NR5wykJENl3MI2d6Q== X-Received: by 2002:aa7:cb09:: with SMTP id s9mr17885356edt.379.1641454211442; Wed, 05 Jan 2022 23:30:11 -0800 (PST) Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com. [209.85.208.53]) by smtp.gmail.com with ESMTPSA id b26sm277845ejb.201.2022.01.05.23.30.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jan 2022 23:30:11 -0800 (PST) Received: by mail-ed1-f53.google.com with SMTP id f5so6140230edq.6 for ; Wed, 05 Jan 2022 23:30:11 -0800 (PST) X-Received: by 2002:a17:907:2ce3:: with SMTP id hz3mr44523902ejc.737.1641454210949; Wed, 05 Jan 2022 23:30:10 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: james@asgrim.com Date: Thu, 6 Jan 2022 07:29:58 +0000 X-Gmail-Original-Message-ID: Message-ID: To: Vincent Langlet Cc: PHP Internals List Content-Type: multipart/alternative; boundary="00000000000028a74405d4e4d7d2" Subject: Re: [PHP-DEV] RFC: Stop to automatically cast numeric-string to int when using them as array-key From: james@asgrim.com (James Titcumb) --00000000000028a74405d4e4d7d2 Content-Type: text/plain; charset="UTF-8" On Wed, 29 Dec 2021, 15:42 Vincent Langlet, wrote: > > I recently discovered that an array was automatically casting > numeric-string keys to int if it was possible. > Having had to track down bugs numerous times over the years, I completely agree this is unexpected behaviour, and would be in favour of it being amended. It is quite a BC break indeed, and both Orklah (Psalm) and Ondrej Mirtes (PHP Stan) agree that the issue is that it's a difficult issue to identify with static analysis (see https://twitter.com/OndrejMirtes/status/1478971968636567552 for some thoughts). As always with type juggling related discussions in PHP, I expect any RFC to be contentious and heavily discussed ;) I expect the main detractors would be the BC breaks, and people might not think the BC break is worth the pain. Just thinking out loud, being able to identify an array type might be a way forward here (using "syntax" already in use by static analysis tools in docblocks, for familiarity), e.g. private array $property; This might "turn off" the automatic type juggling behaviour, for example. If the existing strict_types=1 mode is on, this might fail: $this->property[3] = "hi"; If strict_types=0 or not declared, the key would be cast to a string. That said, I know there has been contentious discussion on this and the related topic of generics multiple times, so don't really want to stir up a hornet's nest there. Great idea, and I'd love to see this fixed, given the countless hours I've wasted trying to track down bugs that are a result of this. But I fear that this would be a difficult one to push through the RFC process, sadly. I hope I'm proven wrong though! Thanks James > --00000000000028a74405d4e4d7d2--