Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123671 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 8015C1AD8EA for ; Wed, 19 Jun 2024 08:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718785936; bh=5erlTEGJ53H3J5A9uEIGXFbVkd3DhlqQ+VplMlfDtE4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=MWI8cuKvSRRWamXh6VsHir3vx8/69DgmaRO/TmVOmN+bZ/N7uKvbpwt2RO/C8yuad msun2Mho4oPy07+AlPdpZ3vAu1ugRdHTal44C+6RyVfbCDNYVjVmaKpKbqyVIrKVw7 YbkkBd1Fo1c/LW0wdrCovfqDlIB2/y+DhXul/M3U5a9ADjUWv7sUpRH3R+4tU1nHD0 yutHeNePlEfinjQPn+sp9LBrUgrveH+b6Ib25NgQsQQhOk5UBgPu+41UuCGokZQM6v 4fMpNMqSHGH14W6g6GS/ZIxTIIWQQxhZ1fK99Px4+eX5cvvvmqIAJ0yGwcP3pQ9S2+ 8rmnj02QhZopQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 093991801E3 for ; Wed, 19 Jun 2024 08:32:14 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 ; Wed, 19 Jun 2024 08:32:12 +0000 (UTC) Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-52c84a21b8cso550537e87.1 for ; Wed, 19 Jun 2024 01:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718785857; x=1719390657; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5erlTEGJ53H3J5A9uEIGXFbVkd3DhlqQ+VplMlfDtE4=; b=UTFXkjC9LTQcMm/Ia5zCgbUw0s3iUSFsJfYyfBtBkkpOqbyKq9PsPn1U8QXY6dafmg 20QRp/RudQrWESzko2NQZGeAHIHr61mELsS3zrzN4scWIQJ/43Vimd1UdZCOUeK38dPp JCtBV9xiojDo8DPTy3IhzGX7UQAZGHfExsXDLfwHxflPD8FataLIBENNjcvN70xSsrCC /YA8VJC9tvKau+o/fu0zxBN3rSWb4l34FtyBEVVyJd0fq+1TzBBYDtIDeRH//qSJDIrF Vc0sggq9K0bx1kAJMWsdqvQz0Zb/NXHlI3FjU1ivZJRqUZ0BgZCzb7pLWtGLyBIjV4Cl Mn1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718785857; x=1719390657; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5erlTEGJ53H3J5A9uEIGXFbVkd3DhlqQ+VplMlfDtE4=; b=LroyqNP5Ey19K/WkngUK3zp5iRBFeoPeMtLVWqE76af32CovK75vcOKut+RPdamZlF gTNcJUYlTHXfk2Wj6WvCYvGw8yNo+VIodBNovVDSCyjQlFbeBzWeeJFOqoLFhqnRHCtE 3askCEvf6G8ALAv9cL09aY1AK8fpKn+GgxxR8nUGYunk3eLtOiqclbZht7vmYCdhV/Jm 2SdOFNPQHoEefoBYFZ9cdm3AbpmXkQG3OkEZwyUXH/6YkYxEZ9NHYcTXGYLu82iiZNJE WYlJCp2+MP5vLU7vFA2+zzReWA0Au3ob5+Xw7XyWp1EvQ5/GhDYPUWOwaAoY3etemTKC e5Qw== X-Gm-Message-State: AOJu0Yy3fxqxTR0g0k7g8kPVHLAD3VmIx2ldcAjhbGslG7NeeIH7VJvg AVMoeSytP1lajD/QM1L4cOJE9vXHrfOMHASpCpVScMKfRPu7pG+ESa4gL3P0jV/10Tz74KNgdMT KNV7P7zHxrP6yu/5L9QyXqpbSdJOvZVgnbmY= X-Google-Smtp-Source: AGHT+IEfs18Kd9fWOZOj5QEfrnwsy7wHGB7ESAmEBAkvDgyt6NYletgAmzNtbrfYAFgeU9+Mxo1O5NiFLAkpVaWl1u0= X-Received: by 2002:a05:6512:220d:b0:52c:9413:85cb with SMTP id 2adb3069b0e04-52cc4afae47mr1166861e87.32.1718785857304; Wed, 19 Jun 2024 01:30:57 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <6b07cb4b-13bc-4e63-8834-fc782faab01c@rwec.co.uk> In-Reply-To: <6b07cb4b-13bc-4e63-8834-fc782faab01c@rwec.co.uk> Date: Wed, 19 Jun 2024 10:30:45 +0200 Message-ID: Subject: Re: [PHP-DEV] Renaming "strict types" to "scalar type coercion" To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Tue, Jun 18, 2024 at 10:46=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On 18/06/2024 17:37, Robert Landers wrote: > > One thing is clear is that "strict types" may be a bit of poor word > choice and gives people a false sense of security that it is "safe" or > "more correct" when this obviously isn't true. > > > I totally agree with this sentiment. I don't think it should be called "s= trict", and I don't think it should be "on or off" either. > > If I had a time machine, I'd propose something like: > > declare(scalar_args=3Dcoerce); > declare(scalar_args=3Derror); > > Or perhaps: > > declare(coerce_scalar_args=3Dif_safe); > declare(coerce_scalar_args=3Dnever); > This is nice. I like it :) > > > But... > > > Thus, I'd like to propose, for PHP 9, simply renaming it... > > > I'm not sure the pain is worth it. We'd have to introduce support gradual= ly, probably not phasing out the old name until 10.0 at the earliest, so yo= u'd just end up with more confusion with people not understanding if they w= ere the same thing, which one to use in which version, etc. > I honestly don't know how the deprecation would work, or what makes sense. Supporting both makes sense and as long as the behavior stays exactly the same, and they are both set to the same thing, that would probably be fine for awhile. Is it confusing... I wouldn't find it confusing unless I was working on something that supported <9 and >9 and eventually 8.x will EoL and then it won't be so confusing anymore. > > Perhaps it might even be worth adding a secondary vote to flip the > default, such that if you want to "old" behavior back > > > You're falling into the same trap you're describing: assuming that strict= _types=3D0 is an "older" mode, or a "worse" one. Both modes were introduced= at exactly the same time, as a direct choice to users between two differen= t styles, which had been proposed in competing RFCs. > > Changing the default, and the name, but keeping the same behaviour, would= just be a huge mess. > > > Personally, I would rather unify non-strict and strict in some way that m= akes sense > > > I think this is where we should be focussing our attention. We've had som= e great RFCs over the last few years tightening up some of the weirder exce= sses of PHP's type juggling system. I've been mulling this around in my head last night and this morning. I think I have something that makes sense, based mostly on information loss. Essentially, an int could become a float (within some limits), but a float can only become an int if it is an int itself. The same concept of a string, where "123test" couldn't become a number because "test" would be lost. Booleans are tricky, but I'd be inclined to keep it as-is; otherwise, the BC break would be unbearable. I think something like that would logically make sense. Whether or not it would be feasible to implement in a performant way, I have no idea (but it would be nice to clean up that area of the C code since it's a bit of a tangle, IMHO). Interestingly, we could still do normal coercion but just warn when there is information loss. Then, people can ignore/catch those warnings and do whatever they want with them. If information loss is what you want and you want to get rid of the warning, you can simply add an explicit cast, but it would be nice also to adjust casting so you can do (int|null) $value; // or (?int) $value so null won't be cast to zero. But that should probably be a totally separate RFC and out of scope atm. > > With a tight enough definition of "numeric string" and other coercible va= lues, I think "mode 0" could be strict enough that "mode 1" wouldn't feel s= o necessary. > > Then again, I was broadly in favour of the original coercive-only proposa= l for scalar type parameters, and there are those who felt strongly on the = other side. The debate was extremely heated, and I'm not in a hurry to reop= en it. > > > Regards, > > -- > Rowan Tommins > [IMSoP] Robert Landers Software Engineer Utrecht NL