Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117695 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33742 invoked from network); 8 May 2022 05:14:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 May 2022 05:14:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 07267180041 for ; Sat, 7 May 2022 23:52:45 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15576 212.103.64.0/19 X-Spam-Virus: No X-Envelope-From: Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 7 May 2022 23:52:43 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 1AFB54405D for ; Sun, 8 May 2022 08:52:42 +0200 (CEST) Authentication-Results: ext-mx-out003.mykolab.com (amavisd-new); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:references:content-language:subject:subject :mime-version:date:date:message-id:received:received:received; s=dkim20160331; t=1651992761; x=1653807162; bh=JucFW82zC7WhBcUK jg/TYdZlma65fou+W2ZKUvetPXA=; b=RgPM58k6H9gM1r+f7+v0xy8bj5nFayoa m7faYi3VkzggaQA0VcdT30hngO8bizKxuGQ6YHTBlemy4WfAR78PZBpApcFatnpW r/89eORFf2TKCJtCtMDtfhFFqhg5laIzaobJ7a3sWqOyyOXtdC3FUrziJByYRLST UA2Ca34FmTq4vp5bsN88K9329kQrcA3mf+0qzyw2Tv/jIdGJf/LZhMkL7G6CBRgu Xhd/3K3iMozOHopnWM9K9+Xbqv0uiNFTRBCqEDqCn6tynwgqUDMFtfNpB7JKYBfd zEJdQOBMYUS328IgY+Bd3gjzB8fUE5BfzwachZdL9qZ2veEnGPtQXnWoqFhBMAPx b/jeKHT6lHmigfKPac1YnPV/uRalciRLMAJ0JMbsFKA3KC9o6X0VQX9jiyQWZh2E Pi9bjvrvgChAgD4EF/48AljLZrb2ydlefOmWtxe8WGlsORXhgnDCvwJPCbdGR3xz LKF/z54Sc1wKZWwFiXhSLCwDfWs68irbe3kQq2Y8ajvH6N/GVG0v82bAX5UUbY0V Zf2NDl/6EhSFcdFbTjjVk4SWDLRlq6tKL+UvYYdi3vnYz54/eVTplmlyyoF6/0EG aIQCYB13QSN5d/8VIGCKFR7T3bylBR810Z7vI9kldDz6X0yeNO+TubUfR+8TLL8i tkyIlEau5zw= X-Virus-Scanned: amavisd-new at mykolab.com Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out003.mykolab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mFC-NYNjntIQ for ; Sun, 8 May 2022 08:52:41 +0200 (CEST) Received: from int-mx001.mykolab.com (unknown [10.9.13.1]) by mx.kolabnow.com (Postfix) with ESMTPS id B1BC343FA5 for ; Sun, 8 May 2022 08:52:40 +0200 (CEST) Received: from ext-subm001.mykolab.com (unknown [10.9.6.1]) by int-mx001.mykolab.com (Postfix) with ESMTPS id 43A94D5C for ; Sun, 8 May 2022 08:52:40 +0200 (CEST) Message-ID: <5598bad8-4e1a-7638-d3aa-36b02568d1a8@alec.pl> Date: Sun, 8 May 2022 08:52:37 +0200 MIME-Version: 1.0 Content-Language: en-US To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] NULL Coercion Consistency From: alec@alec.pl (Aleksander Machniak) On 07.05.2022 23:11, Jordan LeDoux wrote: > What exactly would be the purpose of `?int` if this RFC was passed? To pass > the value as null instead of 0? That's it? Yes. No change here. > What about `int|float`? Which one would it be coerced to? What happens if you pass FALSE to such an argument? int(0). The same would happen with NULL. > This pretty radically changes how typing itself > would work in existing user programs. What I'm saying is that for such a > radical BC break you need to provide some compelling justification. If coercion is possible it should be done as it is done for bool/int/float/string. Inside the function you can still trust the variable type is as expected. The only difference is that it will not throw an error on NULL. Right now you can still use your function "incorrectly" and not get an error, e.g. if you pass FALSE to it (I understand NULL might be more common). And, if you use strict_types=1 nothing changes for you. I don't see this as a radical change. Definitely not more radical than making the code to throw errors where they were not thrown before (no matter how long the deprecation period was). So, imo the BC-break argument is not that strong in this case. The consistency argument is also not that strong (but here probably more in favor of the change) because as it was mentioned already current behavior is consistent with some things and inconsistent with others. The essential question is whether we want more of "weak-typing coercion" or not. More would mean that there's no breakage for existing code in PHP9 (essentially only 8.1 would be "broken" (because of the deprecation notice) so people could just skip it). No need for ugly code like "$var ?? ''" everywhere is also a win. Ok, this was my take, now I will shut up. -- Aleksander Machniak Kolab Groupware Developer [https://kolab.org] Roundcube Webmail Developer [https://roundcube.net] ---------------------------------------------------- PGP: 19359DC1 # Blog: https://kolabian.wordpress.com