Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117704 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28031 invoked from network); 9 May 2022 09:49:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 May 2022 09:49:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 59827180041 for ; Mon, 9 May 2022 04:27:44 -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-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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, 9 May 2022 04:27:43 -0700 (PDT) Received: by mail-wr1-f51.google.com with SMTP id b19so18974777wrh.11 for ; Mon, 09 May 2022 04:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=CBfGwJCgwlT35jlfgHSX9ggtuM/zKM8axlfjD0YrRHo=; b=igemN2hNWAyn2NK06LhHaR/LwO2HLZ1HfOAq38DKh74XvU1dZo6oGal93OZXYN8M2g FX0wraK65q5auWEgZ7VhgVOPMRYZMNJ74w+Bsha+tL8ttVOAis8KrjRjgKRUBRwkNgKd NijnSSslBC3ou9RJAUasLesQ8BY75k68fzpt8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=CBfGwJCgwlT35jlfgHSX9ggtuM/zKM8axlfjD0YrRHo=; b=DEirQhcfZMh9naPyRA5c123InYk3Ui8SCvNvN7N3VC/EpOaJ0pAcnQrWg9By6uVHEk 1bU+M1KBGeQUP0pmgjCUAH02vCbc0GRKruKDdoMiNakEUEP+faVnmPjKWIBw6iR2zZin qO+Zp6EUNpZQdPqSFE+YqN6cvMpf/S58t6atmsRQ0AWlzOJnsshf1750QukYWp1n/E76 /cG7Z3B1p2mkdOLDqxzTI8+0diDA8c4l4yLuJbE7sVwxSokxxpNj3lzGLhQxbg8ElQPx 0S2DY5Zl7oxg4hcsdO/2gg/PqrhFUQHYo7rmlhNSnr5/MU/57oqr6g9RpBNIy/WrQOm6 WkpQ== X-Gm-Message-State: AOAM5321kr0sQ/ytTrQ7xMITwyGCgQwAT52p7aoJ7OlKIzJ+nFkxnktD XTwkaewdu90aYxHv5CgNXTcp906PJDwErg== X-Google-Smtp-Source: ABdhPJzC70JtRxq0NoC5CO992WV+H4994RDvdmFWkTSz60Vis12DyFPngx/PwgyAgF8WBSYGeg9q6A== X-Received: by 2002:adf:dc0e:0:b0:20c:8a3f:b523 with SMTP id t14-20020adfdc0e000000b0020c8a3fb523mr13489790wri.201.1652095662323; Mon, 09 May 2022 04:27:42 -0700 (PDT) Received: from smtpclient.apple ([94.173.138.98]) by smtp.gmail.com with ESMTPSA id h9-20020a5d4309000000b0020c5253d8f0sm11201348wrq.60.2022.05.09.04.27.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 May 2022 04:27:41 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_6E1A63BF-35BC-4921-8D4B-7A9A6EE2775B" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Date: Mon, 9 May 2022 12:27:36 +0100 References: To: PHP internals In-Reply-To: Message-ID: <61DD2793-12BF-4829-9915-E6A86BAB98F3@craigfrancis.co.uk> X-Mailer: Apple Mail (2.3696.80.82.1.1) Subject: Re: [PHP-DEV] NULL Coercion Consistency From: craig@craigfrancis.co.uk (Craig Francis) --Apple-Mail=_6E1A63BF-35BC-4921-8D4B-7A9A6EE2775B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 7 May 2022, at 18:16, Aleksander Machniak wrote: > On 07.05.2022 13:29, Mel Dafert wrote: >> It is exactly user-defined functions that this RFC introduces = breakage for. >> The behaviour to throw on null in user-defined functions exists since = PHP >> 7.0, and is being relied on. Changing these now would introduce = behaviour changes >> that are harder to find than new type errors. >> Using strict typing isn't an option either/would be just as much work = as auditing >> the changes this would introduce. >> It may be that user-defined functions should have accepted null to = begin with in >> your opinion, but that still makes it a breaking change now. >=20 >=20 > Indeed. I suggest to add a note to "Backward Incompatible Changes" = section of the RFC. This changes the contract, but does not throw new = errors in existing code. Thanks Aleksander, While I'm emailing Mel off-list about a more realistic example, I've = added a simple example to demonstrate a BC break: = https://wiki.php.net/rfc/null_coercion_consistency#backward_incompatible_c= hanges = ``` function my_function(string $my_string) { var_dump($my_string); } try { my_function('A'); // string(1) "A" my_function(1); // string(1) "1" my_function(1.2); // string(3) "1.2" my_function(true); // string(1) "1" my_function(false); // string(0) "" my_function(NULL); // Throw Type Error } catch (TypeError $e) { // Do something important? } ``` I believe the example Mel is looking at involves a function that should = return an integer; and later, a second function should only be run when = the returned value is `!=3D=3D 0` (not `!=3D 0` or `> 0`, due to "style = guides telling people to unconditionally prefer triple equal")... that's = all working fine, but sometimes the first function can return NULL (I = assume that indicates a problem), where it's useful to have the second = function throw an exception when this happens (so no more processing = happens, and it can be investigated). While I think there are better = ways of handling this, I'll work with Mel to get this example into my = RFC. Personally I think these are quite unusual, and don't match the size of = the BC impact we face when internal functions (that have been accepting = and coercing NULL since, well, forever) start throwing fatal type errors = in 9.0. Craig --Apple-Mail=_6E1A63BF-35BC-4921-8D4B-7A9A6EE2775B--