Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121631 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8707 invoked from network); 10 Nov 2023 10:47:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Nov 2023 10:47:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BC033180087 for ; Fri, 10 Nov 2023 02:47:29 -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,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 (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 10 Nov 2023 02:47:29 -0800 (PST) Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5098eb6690cso2241473e87.3 for ; Fri, 10 Nov 2023 02:47:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; t=1699613247; x=1700218047; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8vnfT0Wy+nbYNFGdxPKukoPyi6S+/YNC3zTW+1cUCB8=; b=M3qf24apk2LCnT5gLmSU/TEb/UB7pwZSWRKhDa1yUYwUDUYyRMlBqbe357sRxEsTrh QKZpKEhYjPi73Y+zYwEfxzZU0EkAf4DAN49p4r/HYljjtTGtmRwWw6uaAM1eSJCxSZTa PPy9NI5MO0+RMUkT0xhT6KokBx3TNYCcSsoJE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699613247; x=1700218047; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8vnfT0Wy+nbYNFGdxPKukoPyi6S+/YNC3zTW+1cUCB8=; b=IKkbazq8LXTW3DCGvzWFT5kaS9T6DHBm4FTTBUgtld0YZ8TYqcGRSMgrAkXyNjyQ/A rRRXRCO/BpFlI5V2jpihvfs3VmekYlDrw8RxdC2DJAVGgZ/AJkRDeDgMYgJIza3oxpHY GJtV7kO0xZEVtT2ztNGFItzCtay3u27AfQDEg9Bfy+3ikaTbjnePgSl8MAbOqzI8qmsQ ODRxfEMpB4ndMdA0iM6FtNMcNYIJTB7qjArC9zwgHjVKpMBg2FSwujgOAXjTAR5vCPXo NzCYM9GLe9VtTGSg3R8LIrt13AdLZ8XuU7ns573KOVG9SfF/be3t+dfIg2qyfdzVBcdh jtEQ== X-Gm-Message-State: AOJu0YzdWAQnijjtuyfnR065TsJy7pkqfXRmN+4EGFInhiz5k0Smhl2A zTS9unP5GO5x+Q4dDKZbrXWMKw== X-Google-Smtp-Source: AGHT+IGUeVguX5p38dWSaBTaKSeB1Eg0gLcvE+4wc0oO371VVJGJmrBMZNP5ON+X74S6li/WDP/ayA== X-Received: by 2002:ac2:58db:0:b0:507:9855:bc68 with SMTP id u27-20020ac258db000000b005079855bc68mr3414381lfo.37.1699613247238; Fri, 10 Nov 2023 02:47:27 -0800 (PST) Received: from smtpclient.apple ([92.238.103.248]) by smtp.gmail.com with ESMTPSA id r21-20020a05600c35d500b00407efbc4361sm4794067wmq.9.2023.11.10.02.47.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2023 02:47:26 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.200.91.1.1\)) In-Reply-To: Date: Fri, 10 Nov 2023 10:47:16 +0000 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <1A044D32-019A-4152-A3C0-3F393974AC3B@craigfrancis.co.uk> References: <5144806E-E21F-4AF8-B9A2-0161561A6B9E@craigfrancis.co.uk> To: Kamil Tekiela X-Mailer: Apple Mail (2.3774.200.91.1.1) Subject: Re: [PHP-DEV] Passing null to parameter From: craig@craigfrancis.co.uk (Craig Francis) On 9 Nov 2023, at 16:08, Kamil Tekiela wrote: > Automatic casting of null to other types is a handy feature and = deprecating it brings no benefit to anyone.=20 That's what I thought, but for some reason, casting null is deprecated = only when it's provided as an argument to functions, all other cases = it's fine... weird right? > Instead, if you want, submit a proposal to reverse the direction. No point, people will vote against, and will just entrench their = position (people like to think they are right, this would involve them = changing their mind; and because everyone voting is almost certainly = using strict_types=3D1, it won't affect them, and they will see it as a = way of pushing "lesser developers" to using strict types). > This should only apply in loose-type mode. Yep, of course. > and it would make nullable types useless. I don't think so, nullable would allow the NULL value, and the = non-nullable would be coerced, just like the other types: ``` function example(string $b, ?string $c, int|float $a) { var_dump($b); // string(0) "" var_dump($c); // NULL var_dump($a); // int(5) } example(NULL, NULL, '5'); ``` > Such a change could also be complicated to implement given how = ambiguous it would be. It always worked that way (for internal functions) - for arguments that = accept a string, cast null to an empty string; if it accepts an integer = then it's 0, etc. > But if you can outline tangible benefits and write a PR to show how it = would work, I think the community would review the RFC.=20 I can't be trusted to write C, so can't do a PR (other than to revert = the last commit, which isn't quite right)... I did draft an RFC, but I = just got complaints: https://wiki.php.net/rfc/null_coercion_consistency > As for the negative responses, it's probably because it's been many = PHP versions since the nullable types were introduced. People accepted = it and are generally satisfied with how it works. People here are likely to be using `strict_types=3D1`, but the majority = of developers use PHP as a simple scripting language, and don't see the = benefit to strict type checks (just to note, I do, but I'm not talking = about me, I'm looking at the amount of code that will not be able to = upgrade to PHP 9). > So unless it's causing some serious problems for PHP developers or = users, I think it's too late to change the design of the language. At the moment it's causing deprecation log entries (which are ignored), = but the problems are everywhere, like the following (Laravel), is this = really that unreasonable? ``` $a =3D trim($request->input('a')); ``` This will start getting Fatal Type Errors in 9.0... and finding these = "mistakes" is close to impossible (phpstan doesn't find them; psalm = requires high levels 1-3). Craig