Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117183 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98415 invoked from network); 1 Mar 2022 16:36:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Mar 2022 16:36:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0764C180542 for ; Tue, 1 Mar 2022 09:57:48 -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=-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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 ; Tue, 1 Mar 2022 09:57:47 -0800 (PST) Received: by mail-lf1-f47.google.com with SMTP id j7so28211377lfu.6 for ; Tue, 01 Mar 2022 09:57:47 -0800 (PST) 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=VEEiZ4vuOQg59Ss7Hrf2DOBXrJNPWZMnn+pjgtCTcW4=; b=FrxzZkXZSVO/adn2hSTzjj5YRvzjX8QmhoIPakQhfWv9AMwKWJqh4PJmoLURDSOl4p RM95VgK9XpoblbohL5bZZiBJSuSOTovK+2p4i8Jb0cZ20EYIU5jPeRbbq/Zp2LR+yzTE o9jHH6EL5el5NQSQHhxIPoQdWdPaTk3SnLm60= 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=VEEiZ4vuOQg59Ss7Hrf2DOBXrJNPWZMnn+pjgtCTcW4=; b=lawCXTiabOkVqsJW4WUduI4ezC5LCqdeYrkywG8t+i8E/j8OUfK/5YXkrUM7R7aFlW 4uu0tUjfVGDVfeM4sLbnYQnhTHi2fW0e37xYvZYxx6G5Gj1hqsYCNOJG1cSsFUV24Vc/ Dek9AqlJj1YGuDbLGxFwncomt7nqoL42JA/7eVTI9opS7Jvn/F1ocEXPziN4Ff3ZoVYP DQQi7t4euqQD/rteFsOy6TRsdATGL1afpVLSIDqLNFHl8ylptbBpqTI34hId1LMQcvzN yC9/3UaEuUZWpppeFKDhYbLNHpK/JLJz0r6HXRs/SgY4a8gJH4k89dI0JWi42/n/G5K5 qlrg== X-Gm-Message-State: AOAM53032eeRKn17Z2nY9pMmvJTsB7ovzRYYvi7HcXivgo7aJF/1PaTX kjkn/QgM6xYY9+1UQYRbSIuC9NQld9bqGVeD/Ra1zw== X-Google-Smtp-Source: ABdhPJyd2A7QCf8BIWheftYrMWDgQXXs3PmUMPxGv12I/3ORG1n6SqejxzHqWa41cYrvp4gDg1jYO+rooyacadrPIoQ= X-Received: by 2002:a05:6512:92b:b0:445:81a9:b9e0 with SMTP id f11-20020a056512092b00b0044581a9b9e0mr12748883lft.302.1646157465731; Tue, 01 Mar 2022 09:57:45 -0800 (PST) MIME-Version: 1.0 References: <983552d8-11f1-b5bc-fb82-148347982fda@gmx.de> <5494eaa7-2fa6-8364-9683-a2c8c9789d81@gmail.com> <69642616-72b7-44fe-97a7-27ae03bc8fce@www.fastmail.com> <7fbed755-42e2-d023-285f-39863a97f297@gmx.de> <3665C848-B4C3-4528-AEFA-02C868748AA8@cschneid.com> <0b5bc29d-3814-0e1d-b94a-47790019c778@gmx.de> <5463E9FF-309D-4CFA-B709-81498B934059@cschneid.com> In-Reply-To: Date: Tue, 1 Mar 2022 17:57:34 +0000 Message-ID: To: Kamil Tekiela Cc: php internals Content-Type: multipart/alternative; boundary="000000000000fd614605d92be6ba" Subject: Re: [PHP-DEV] Allowing NULL for some internal functions From: craig@craigfrancis.co.uk (Craig Francis) --000000000000fd614605d92be6ba Content-Type: text/plain; charset="UTF-8" On Tue, 1 Mar 2022 at 14:12, Kamil Tekiela wrote: > Hi Craig, > > > No, there is an inconsistency which leads to a backwards compatibility > issue, and I'm trying to fix it. > > Which inconsistency exactly do you have in mind? > Ok, let's try with code (I'll skip using variables): https://3v4l.org/gvXmr Before PHP 8.1 all 5 forms of coercion worked for those not using strict_types... now a form of coercion (from NULL) has been deprecated, and for some reason it's likely to trigger a Fatal Error for everyone in 9.0 (while this is appropriate for those using strict_types, who are typically using static analysis; it's not appropriate for everyone else). The discussion is about passing arguments to functions. We are not > discussing type juggling or type casting. To clarify the whole thing let's > list out the key points: > > - PHP has a concept of scalar types consisting of these four types: > string, int, float, bool > But I am talking about Type Juggling: https://www.php.net/manual/en/language.types.type-juggling.php Or as noted under the Strict Typing documentation, where I've been using the name "coercion": https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict Anyway, as noted earlier, developers who are not using `strict_types`, they do not care about PHP's definition of what a scaler is... they don't generally think about variable types (ish), and they don't really see type coercion happening, they just expect it to work... yet, in 8.1, coercing from NULL with internal functions is now deprecated (still works with non-strict comparison operators though). The only inconsistency is that PHP's internal functions silently accepted > NULL values for non-nullable parameters. This will be addressed in PHP 9.0. > Adding a type check for scripts not using `strict_types` it will make it much harder for developers to upgrade to PHP 9 (not good). While sticking strval() everywhere in itself is an easy change, due to the numbers, and difficulty in finding them (note the lack of tooling), it's very time consuming to update (your code may be fine, but that's not common). Changing the signatures of some functions might be reasonable but, as few > others have said, it's not the solution we want to see because it feels > like a hack. As I have also pointed out off-list, in many cases making the > parameter type nullable would not make any sense as passing null to certain > functions is a clear bug. It would also have an impact on strict typing! > Yep, I agree, see previous emails. We could also reclassify NULL as a scalar type but that would be a > fundamental language change. It would likely be a bigger BC change than > fixing the current inconsistency. > I doubt we need to change the definition - I doubt many people would care what the documentation says, and there is no need to modify the output of `is_scalar()`, even if I personally find it a bit weird (but this isn't about me). We need to accept that PHP has coerced NULL to an empty string, integer 0, float 0, and boolean false since, well, forever... and developers not using strict_types have used this feature all the time (nearly always without thinking about it). By the way, your statement that "Coercion works for string/int/float/bool, > *and* NULL." is invalid. Coercion is defined only for scalar types as I > have explained above. Type juggling for most types from NULL is defined, > but that is not what we are discussing. > Erm, we are discussing type juggling "from NULL"... as in, NULL is being provided to these functions, and the value is coerced from NULL to a string/int/float/bool, as documented: https://www.php.net/manual/en/language.types.string.php "null is always converted to an empty string." https://www.php.net/manual/en/language.types.integer.php "null is always converted to zero (0)." https://www.php.net/manual/en/language.types.float.php "For values of other types, the conversion is performed by converting the value to int first and then to float" https://www.php.net/manual/en/language.types.boolean.php "When converting to bool, the following values are considered false [...] the special type NULL" Craig --000000000000fd614605d92be6ba--