Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121648 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53714 invoked from network); 10 Nov 2023 20:00:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Nov 2023 20:00:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5CF17180087 for ; Fri, 10 Nov 2023 12:00:55 -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,FREEMAIL_FROM, 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-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 12:00:54 -0800 (PST) Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-408425c7c10so18413015e9.0 for ; Fri, 10 Nov 2023 12:00:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699646453; x=1700251253; darn=lists.php.net; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=Czhi/om95tm1hP9ttn83dIChtZXxc9ToHUAEL45Uo7I=; b=m1RoSiTwfIhL6iV35NS/uOyzA/otA18ZAXKMMbzw+8rgy8xmXFUiEeeCBpRIzVVZ0V saXqdlmLB1metfgBwc6lq3FMmHMmfE2ZXM9+hGqF//9scboDmFjzqigghzRWw3Uaf7hM l5jyiMVlFXr4hz9Ly4P13UIe77t3AnlhZ/gXX8PdOeHOs+u8zciStuvAFveKNki+4vRs MbUrTU92xF0gYfe+Uuf6EsAwcGIybbevKCfo0a5wyOUIKWJgBSpmlyIqKWiB5sZgVByX VYH3zgBXNqECEquuLSec4obTlmNikMqZiKK7Pq+TsotRQm17NiOahrvCmYsOi3VZJdrt 4OaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699646453; x=1700251253; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Czhi/om95tm1hP9ttn83dIChtZXxc9ToHUAEL45Uo7I=; b=TIZGDzPFe5+WXWZCmPXWkUFlo2Wznet9mcnB3Nn4gytz/7GJPd0wMw5neDgi3613nM UjB1QGbY1oeqGxcf11qf5SuFN8cBW3P1pxn6zc1gV4hu6zCfVUS0e+k47YtgL7ZyHG9j qL9xuUqp+FxyO1knf4j9eRkkXdmP6g7igpKkdZXEb2pIVoe92Tk+MlA8cauSARki+9Vj gLyVtIZ/giAXtYZXwCDiOJvBUdqYCl3C/JQXVNj+AuJ77R1hJaZtnnYGWFqp2wq2b/st 97RCZs+7eZpj5ozNCzX9CKMgdAZNBzm732MqziB6Q7dwzbwueL9vNC/mGxi+KyHAdCTq 3o8A== X-Gm-Message-State: AOJu0Yz65b06kATmuEPBPCwcJ/LeIT0KO0ZtR1lFL2BFqbWesLydPhhL xfRcP0YLB31EWOdXmsyRHkECnvF0QFI= X-Google-Smtp-Source: AGHT+IEA8hJx/AE1GVdsUAv1QkWwUxB2Fs/u1Uy59paLR5F8wyAcHP4iHVNBLhpeu1xEqQG/WzArNA== X-Received: by 2002:a05:600c:1c19:b0:408:3707:b199 with SMTP id j25-20020a05600c1c1900b004083707b199mr264255wms.3.1699646453243; Fri, 10 Nov 2023 12:00:53 -0800 (PST) Received: from [192.168.0.22] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.googlemail.com with ESMTPSA id p17-20020a05600c469100b004064e3b94afsm6210750wmo.4.2023.11.10.12.00.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Nov 2023 12:00:52 -0800 (PST) Message-ID: <0fe42819-e4dd-4329-b834-ed3295167e56@gmail.com> Date: Fri, 10 Nov 2023 20:00:50 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: PHP Internals References: <5144806E-E21F-4AF8-B9A2-0161561A6B9E@craigfrancis.co.uk> <049d4758-def2-4a29-9e02-afa61e5b977e@gmail.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Passing null to parameter From: rowan.collins@gmail.com (Rowan Tommins) On 10/11/2023 11:29, Craig Francis wrote: > strict_types=1 enables strict type checking While it's not exactly false, this statement is misleading in a really important way. That's not your fault, it's just that "strict_types" is, in hindsight, a really terrible name. If I had a time machine (and a lot of patience to wade back into the debate), I would advocate naming the modes as follows: * declare(scalar_params=coerce) * declare(scalar_params=assert) This would have made several things clearer. 1) Although asserting a type is in a sense "more strict" than coercing it, the "coerce" mode actually rejects more inputs than an explicit cast would. 2) The settings were never intended as a change to "the type system"; they don't change the behaviour of anything other than certain arguments passed into functions. 3) They only change the behaviour of a small number of new type keywords added to the language at that time: "int", "float", "string", and "bool". It governs the way these types interact with each other, and not anything about any other type. Most relevantly for this discussion, that list does not include "null". At the time, the language already had type declarations on parameters for "array" and class/interface names, and those already disallowed null values. Note that this isn't a given, as many languages treat "null" as a valid value for any object type; recent developments in C# suggest PHP got it right for once by disallowing that from the start. > I never understood why NULL was considered a complex value like a > class/callable/array, when it's more like a simple bool/int/float/string I think you are misreading the quoted passage. It's not saying that null is similar to the complex types, it's saying that the handling of null values should be consistent between parameters marked with those keywords, and parameters marked with the new keywords "int", "float", "string", and "bool". In actual fact, we could probably have narrowed the scope of the setting even further, because there are two cases that most people care about: * coercing int to and from float (which is allowed in both modes anyway) * coercing string to and from int or float (e.g. getting an ID or a price from a URL or API response) So maybe we could have had: * declare(numeric_params=coerce) * declare(numeric_params=assert) That would make it even clearer that the question of whether trim(null) is a meaningful operation is a completely separate debate than anything that the declare() covers. Wherever it is used, "null" is a confusing and often controversial concept. In different contexts, it is used for different things, and has different ideal behaviours. It's a whole debate on its own, and bringing in other types of coercion just confuses the conversation. Regards, -- Rowan Tommins [IMSoP]