Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117517 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8569 invoked from network); 11 Apr 2022 16:50:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Apr 2022 16:50:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CD4F31804AB for ; Mon, 11 Apr 2022 11:22:29 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 ; Mon, 11 Apr 2022 11:22:29 -0700 (PDT) Received: by mail-lf1-f42.google.com with SMTP id u7so11053467lfs.8 for ; Mon, 11 Apr 2022 11:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DaStHy9dPTZZbQKahDId0F/1lwDvYUwkhm1CMTEOLi0=; b=NpUzJ/8xlS+6sD4YioEIvv3iVAboTzjrxsiuXhBrhmywwE/tDr6ZZ5eI8jvGMLiaqK sEnMgzfp35BU7cN4qw1V7NkT+JpBC7M23w0bGxrqzknBjrBU8hCcUgjQ4n3htR73Lcjx gwgKRFu6/mveqf16A28hG14pTfpCaMF8Hk5ic= 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:from:date :message-id:subject:to:cc; bh=DaStHy9dPTZZbQKahDId0F/1lwDvYUwkhm1CMTEOLi0=; b=zlCzeoj/hKg2nI6ylQOhVgsSUCh0AxqlfFejjB8vUY0moIX8++b7NPvu0d+lQ93ea6 gweUXyu2tA5UJTcPZr+fXZijT4jvtowCntgdxTNWR0/JpYgUXpjtkiPfynhwP9+rRuf/ 9Fx5daJBtEDOBqW1lWnktpBr8sO2lghkTc0dEkndbNTCbJ1oitzrPsLePKL+TplssE4Y s2M6d4ZKUI+3zOKG18Jd4X025ihbWFaqt6gWOyfhXMlrudvEU3m0MCEmIQvlqxaniLVV Jmiw1Pk3bsnlYWK3eHjum/tNAOrF/NIjr/h3Gx+i0ZiPVHR581kTcxDUbJ4QsQclZrNN FNrg== X-Gm-Message-State: AOAM5303fSotwf4m24EuwOO9uhMby1cOP4c52HVkpHy1M8WwoNJFlg+i zlvxPebMRt2Eu3wZvQbiXwGTSJxwOT0dB4YR3+LvqXZEF6GxQg== X-Google-Smtp-Source: ABdhPJwMlBTtfiIiBo+CVj/YL3VFXtWym+hrRd6gkYHeNQT6RW8VbYd8h7U+H4GBdDChiP59b6L7sH6R4/cvOrRrGAo= X-Received: by 2002:a05:6512:3e1b:b0:46b:a4d3:7da1 with SMTP id i27-20020a0565123e1b00b0046ba4d37da1mr5224368lfv.302.1649701347124; Mon, 11 Apr 2022 11:22:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 11 Apr 2022 19:22:16 +0100 Message-ID: To: "G. P. B." Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000c7fed305dc650609" Subject: Re: [PHP-DEV] NULL Coercion Consistency From: craig@craigfrancis.co.uk (Craig Francis) --000000000000c7fed305dc650609 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 11 Apr 2022 at 16:14, G. P. B. wrote: > But the implementation caused a Type Error when coercing NULL for everyon= e >> (even when not using *strict_types=3D1*), this seems more of an over-sig= ht >> > is utterly wrong and was a conscious design choice based on the widely > accepted view that nullable by default like Java is a mistake and defeats > the purpose. > Bit hash... anyway, I've replaced that paragraph (it wasn't clear enough), I just wanted to note how developers not using `strict_types=3D1` would see it as an over-sight that coercion works for string/int/float/bool but not null (despite what the documentation says), and how it's introduced a type check (that they didn't ask for). I assume you're using `strict_types=3D1`, and will be unaffected by this, s= o with all due respect, I'm not considering how you view or use NULL, nor do I care what Java does, I'm simply focused on how most developers use NULL in PHP. "2. If the value can be coerced to the type requested by the hint without > data loss and without creation of likely unintended data - allow" Yep, as noted under the Documentation heading, and copying from the manual, =E2=80=9CPHP will coerce values of the wrong type into the expected scalar = type declaration if possible=E2=80=9D... which it can, and does; for example, co= ercion to a string "null is always converted to an empty string". https://www.php.net/manual/en/language.types.declarations.php#language.type= s.declarations.strict https://www.php.net/manual/en/language.types.string.php [...] but this again brings us back to amending functions to have nullable > arguments, not a blanket change. > As noted in the Introduction, second paragraph, unfortunately this won't work (especially considering the ~335 parameters affected by this)... just taking `htmlspecialchars()` as the most simple example, I asked a few developers who use `strict_types=3D1`, and they did not want `$string` to be a nullable argument, because NULL being passed to this argument suggests there's a bug elsewhere in their code. This view was also reflected in the quiz (the names are links to view their answers): https://quiz.craigfrancis.co.uk/ The breaking change was justified and explained, and voted unanimously in > favour with 46 votes. > The burden of justification is now on your end. > My whole RFC is the justification, from the lack of discussion of the impact (where I will note that I am in favour of its intention of consistency), the roughly 85% of scripts that do not use `strict_types=3D1`= , the almost certainly less than 33% developers who use static analysis, how tools do not and will not fix this problem, how this goes against the documentation, and all of the examples. Keep in mind, if you're using `strict_types=3D1`, great, you're not affecte= d (I'm not either)... however, I work with quite a few developers, and it's causing them a lot of problems, and their current approach is to either disable the deprecation warnings, or to stay with 8.0, simply because they do not have the time to make the changes... I will note that one team has been trying to update their code base, it's about 6 months later, and they still keep adding `strval()` to silence these deprecation warnings (yeah, I know, not good, but it's the easy solution). changing the type system into a broken and inconsistent way, and reversing > a unanimously voted RFC needs strong justification. > I really appreciate your time to read my draft RFC, and I know there is no way I can change your mind, but can you explain how would this be "broken and inconsistent"? Just take NULL to String coercion as an example, the documentation clearly and simply says =E2=80=9Cnull is always converted to an empty string=E2=80= =9D, this needs to be updated to end with "... except when being passed to a function, in which case NULL will result in a Type Error" (I think that's "broken and inconsistent"). Craig --000000000000c7fed305dc650609--