Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117543 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83249 invoked from network); 19 Apr 2022 11:44:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Apr 2022 11:44:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EB010180044 for ; Tue, 19 Apr 2022 06:17:41 -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.3 required=5.0 tests=BAYES_40,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, NICE_REPLY_A,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-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 ; Tue, 19 Apr 2022 06:17:41 -0700 (PDT) Received: by mail-wr1-f48.google.com with SMTP id c10so22437840wrb.1 for ; Tue, 19 Apr 2022 06:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=kcKMRBuUQ45MiFBU8kqydAKQ4q266Rl3wAE1dwsZmsw=; b=GeT9ePj/i0GqIUptCOsuPyegsgZxWuXx4ui5itaQVQ1a+bKBTo/hdzcty3XRQ1g3jc xLJKJJH/OCJGB7B5Vp6WdLwDszC3wxGROm3kZPdImt/z+8M1mDadeKPthfMakHo2ZTIC Ni9v8bssjz/UtxwI1ZjEXgZpKUD8cyFW/KpxS3R5KdIo4wnmI8iipAv6c6eiYrw+0zZN byjcSHFlQbXbI0LsKX+vsRi6CDexZ+4PcJfLOZe7XFVGIWtzcYnFY02jQCEphGP46LV0 Hbc5vsRxcsoxdxK/qTDAy0taF/GmzfQE7FvOu8oTy0j3ZoqP0+v3x8vE047DSJDpIxHD HQCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=kcKMRBuUQ45MiFBU8kqydAKQ4q266Rl3wAE1dwsZmsw=; b=LAbPjqdObjYBVMNQFXrzEpdDXiq4nOmM5Sqk+26IsJjPIXeMGKAGtexeIj4aCsxwS9 EeXNjetuBj+wzPmEIQ95akT2DS9mAEeoFOXR7rK9Ubdpq+m9JtiriuCBB/vgCXxHTN13 /tfhABX8mlnZ+6uk27T7wAJvWEYWFtCuU5qxKyfWBxuomVVTPViW1mrRY0+P9+vcWv0D 4QNkEQfjOQqZoteqcDnAiXao/ZLXImGRGiVCb+0F8Av6L5ecfgmLZXa2onrybTcYdXds QX4bJ9feSIjwy/tEcJjQy3wd7KIEsvzL8SHj9pa7qV7qmJkhMfK52S3nisWGZxAZnebU 6mJQ== X-Gm-Message-State: AOAM530GchB5ZD2wSQCAWY6ApSBrug22SmQD+4gayEj5RAggl5zhTY6k TdSEkqXf8dFbaH+ObkiJgwhbOKSO9pU= X-Google-Smtp-Source: ABdhPJzmVTmh/a61PNLXbKa8VGkZUpJTOH9lwa/AsssCeExuNvrVgKwKdynkMVV+rZqEF/q/4nt4hA== X-Received: by 2002:a05:6000:188b:b0:20a:a7f4:2f8 with SMTP id a11-20020a056000188b00b0020aa7f402f8mr1889520wri.424.1650374259964; Tue, 19 Apr 2022 06:17:39 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id t2-20020a1c4602000000b003917d43d339sm12950489wma.4.2022.04.19.06.17.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Apr 2022 06:17:39 -0700 (PDT) Message-ID: <0b061f28-a087-efd3-8602-424ee03458e0@gmail.com> Date: Tue, 19 Apr 2022 14:17:38 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Content-Language: en-GB To: internals@lists.php.net References: <42D0A480-F262-4F72-9C4D-887762A8D800@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] NULL Coercion Consistency From: rowan.collins@gmail.com (Rowan Tommins) On 19/04/2022 12:34, Craig Francis wrote: > The developers I work with would assume the last definition I think you've somewhat missed my point. I wasn't talking about people's habits or preferences, I was talking about different *scenarios* where null is used to mean different things. Yes, some people prefer languages that "fails early" and some are more interested in "do what I mean", but not everything is about that. > I also cannot explain why NULL should be rejected ... does it avoid > any bugs? Yes, sometimes. Imagine an array of values provided by the user; during validation, those which were optional and not provided get set to null. You then loop through and display those which were provided: foreach ( $fields as $name => $value ) {     if ( $value !== null ) {          echo "$name: $value
\n";     } } Then, you realise you forgot about escaping, and decide to run everything through htmlspecialchars(): $htmlFields = array_map('htmlspecialchars', $fields); foreach ( $htmlFields as $name => $value ) {     if ( $value !== null ) {          echo "$name: $value
\n";     } } Spot the bug? $value will now never be null, because htmlspecialchars() will silently turn the nulls into empty strings. I've also seen the opposite problem: a string function was removed because it was no longer needed, and the code broke because values, including nulls, were no longer being cast to string. Is protecting against this worth the backwards compatibility cost of changing the behaviour, and requiring extra code in other scenarios? Possibly not. But that's different from not having any benefit. Regards, -- Rowan Tommins [IMSoP]