Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121633 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12793 invoked from network); 10 Nov 2023 11:11:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Nov 2023 11:11:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 65E241804B3 for ; Fri, 10 Nov 2023 03:11:28 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,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-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 03:11:27 -0800 (PST) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-5b383b4184fso23034527b3.1 for ; Fri, 10 Nov 2023 03:11:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699614687; x=1700219487; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jSPVJx5KEQ+ULfvit3qC21P9cPslp01XHqJEAyVRKNM=; b=UKq9WJhExRWZ6hEaUZx0/Vun/pZzruv4f9LOeP1gkcPSn+JUbfc1VMGG3tE9VAzMNa 4ZfPzJjPeKGMkJ/rA9MMvsOALODsjEj8c0CN7ZfZ8c5MSjNcCkbsdjNy6/ANMoA2S97/ 2Htd9+c1dyPDskRoIukAaFjkM0z3U6fnQ4Hn0/wyyKI7bU0R2vYMaSkuThxq4wsAL5G1 zgXVbYAr63ryTBtCXUwAASUdKYypTiHr828K175CIVOUtbyJnAcwppYyFIJ1wcNlj2iB Xvl9Avwa/Xd4kImiU3eYlS4RtK922t6+u+ATjMsWbHkH2qLCuBdoepHI9WbTtl7ECR18 cMsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699614687; x=1700219487; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jSPVJx5KEQ+ULfvit3qC21P9cPslp01XHqJEAyVRKNM=; b=eT8jZTtoqMd8LYSAIHSi5/yZpqx8qa9KPFRzkj3fRhyi41r4xZtDtA7fNq6QPRM67d hk9Pzl3I5ezuZRhW098HHLAvIhzZxCanma38E3F8/CEqWCWNCXyh8G9orTNG51lF6+h7 FhDlGntR6nNirsAdOOzGd+3mxpAE9mdgyzMCgdnRG1LUKrxAyMUSeGwIvDvGuEJbe9vZ LFkHloJQw4p50JZkzLoF3WxMHxbBkiSS6ly0bsjbtbk7NOomZOl02hGzQ5zn9D4usMCg txRCcFp1PhTfx5Wahr0lKWBfC+qngUG1NMn5ukqvChBgRcyISXT3H+7P2YYsHWsq+h5B VJzA== X-Gm-Message-State: AOJu0YwgVZtWnLDV+QYc69eWq3YMfR6CygBG9spXW09FMNZKNvhwURn7 GUD0zo9lv6cII0YDBSSU04NREQVVkrzRwF5UtUmnymIFGds= X-Google-Smtp-Source: AGHT+IGLJ3QTeMoOkd5Lqsz9MdJdiLySxIqgr6RfJ6veRa/i5XSENMSzkUbb+SJDYa/+aRr0KVEbXH0btbGa9dxMsb8= X-Received: by 2002:a0d:c042:0:b0:5a7:bff3:6fe4 with SMTP id b63-20020a0dc042000000b005a7bff36fe4mr7244694ywd.9.1699614687047; Fri, 10 Nov 2023 03:11:27 -0800 (PST) MIME-Version: 1.0 References: <5144806E-E21F-4AF8-B9A2-0161561A6B9E@craigfrancis.co.uk> <1A044D32-019A-4152-A3C0-3F393974AC3B@craigfrancis.co.uk> In-Reply-To: <1A044D32-019A-4152-A3C0-3F393974AC3B@craigfrancis.co.uk> Date: Fri, 10 Nov 2023 12:11:14 +0100 Message-ID: To: Craig Francis Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000ad35820609ca6151" Subject: Re: [PHP-DEV] Passing null to parameter From: tekiela246@gmail.com (Kamil Tekiela) --000000000000ad35820609ca6151 Content-Type: text/plain; charset="UTF-8" Hi Craig, Don't get me wrong, but I have a feeling you still didn't understand fully my first message. 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? > No, passing null to non-nullable parameters is already an error. It has been for a long while now. The only exception are some built-in functions that silently ignored that and cast the value to another type. > > 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=1, it won't affect them, and they will see it as a way of > pushing "lesser developers" to using strict types). > I don't use strict types and I am pretty sure there are many more people that don't. I started using them more recently but I don't use them everywhere yet. However this discussion doesn't have much to do with strict types. > 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. > It only worked like that for some built-in functions. That's because built-in functions didn't (and some still don't) respect the PHP type system. However, passing null to non-nullable param was never allowed. > 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 = 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). > It's only throwing a deprecation because we started to fix the built-in functions so they behave like the rest of the language. That's a bug fix, but as I explained earlier it was always an error. That's how the language was designed. Finding it is difficult, I agree, but that's the whole purpose of the deprecation. It's supposed to help you find all the mistakes. The mistakes are only with built-in functions, so the scope is very limited. With all other functions the error is caught during development because of the error. Casting null to other types is not a mistake, but passing null to functions that don't expect it, is a mistake. There's no defined behavior in PHP as to what should happen. Allowing passing null to non-nullable parameters is a big feature request that never was part of PHP. It's not something that was removed, it's something that never existed. Just think about a simple example and how ambiguous it would be. function abc(string|int $p) {} abc(null); What should null be converted into and why? If you as a developer know then you can cast the argument to an appropriate type but on the language level, it's not really possible. So, in conclusion, we are not supporting you because we are stubborn or that we want to force strict types, but because resolving this problem in a way you want is extremely difficult and borderline impossible. Regards, Kamil > --000000000000ad35820609ca6151--