Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119117 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57404 invoked from network); 13 Dec 2022 12:39:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Dec 2022 12:39:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C4C58180503 for ; Tue, 13 Dec 2022 04:39:31 -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=-0.2 required=5.0 tests=BAYES_20,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-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 (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 13 Dec 2022 04:39:31 -0800 (PST) Received: by mail-wr1-f51.google.com with SMTP id u12so15439802wrr.11 for ; Tue, 13 Dec 2022 04:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=q3fNUyjYTsiBmhW2s4UGr25MymRJ752TT1AeWk/fuhY=; b=FCCBaBm7CeW45qGbv3J/YmCNdYpLrh49DtujBzFBLfTqaioDouRj0XXIrOFe2qFpFR iH7SCUtRApf28FXh7SiXeKsSW98fyhumr4AX+fQbSoTdKDAGo/Tx/F02DyeXDMJt7oJY drnY6pnghNEbd4iyNs08+5AJrmD/mrtrZytuKl/6+6vgK6JSHLaG7Xjg/wKDlm/vLv5T llmJsGiJdfZONGGacNbU8a5cVsuE3c2LzeR9KcYxiAJIIvcB2Jdn+jkj1tEC34uZDohf V8N+bQduxypaCBRUO6sdUPtrHVXy+2xWpCItIqAeOsmR+1KEcDRDhU+cX5q1ONQB5bPt XBPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=q3fNUyjYTsiBmhW2s4UGr25MymRJ752TT1AeWk/fuhY=; b=yRsmPI9dmzwoV8FGc0kpkKTGq4WkaKDOTEV1HLJTE1GwFUY2JanARAwy0b+bW1dZRW PbfdCLn7walRlyQz4FBH6vAjc66z/SbDfAZfgorqroB73D7QBEc6PC7DA86ir+Tz1jdY /9SfzE1mirXNd9t1Gz4DjNYo6CwNiblyEkDooKeR4F2zJ6ykzCkRUWtWdu+36wol60CO CieTfbbt4su+Itlt9eR2gHstPjh0N7hRKwm1zw9hcVSs6GmtILXC/odzCnJsfAHbFzu/ aGqS1AztQcyYFxGcTkSwLZRN56U1V4z4oWQJMlTyYQZkMiLYmHV1gKtCo2MZOXueIhkK ew5w== X-Gm-Message-State: ANoB5pkhdPQkvmNUAsQ5Gl7ufB4OqX6Cw7oI2qFlrWg92JOK/4Kcqpqe A3YjsGleTuYOmG6rDvUWDn67ZaeFfpY= X-Google-Smtp-Source: AA0mqf4S/w8Ca8oPG9uEHiQkPyhkWLB0nvC0n6ggoL5rsD9ZztmeFqG0qiCR1YJQOZSEP4NMF64VdQ== X-Received: by 2002:a05:6000:1f81:b0:250:22e4:b8a6 with SMTP id bw1-20020a0560001f8100b0025022e4b8a6mr4052680wrb.39.1670935170191; Tue, 13 Dec 2022 04:39:30 -0800 (PST) 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 h20-20020adfaa94000000b002367ad808a9sm11622672wrc.30.2022.12.13.04.39.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Dec 2022 04:39:29 -0800 (PST) Message-ID: Date: Tue, 13 Dec 2022 12:39:29 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Content-Language: en-GB To: internals@lists.php.net References: <5fe0d8a9-d305-9c9d-ca36-1ca30de87b78@cubiclesoft.com> <38E9E8ED-F266-4EFC-8E17-DDD60F45EADA@craigfrancis.co.uk> In-Reply-To: <38E9E8ED-F266-4EFC-8E17-DDD60F45EADA@craigfrancis.co.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Revisiting RFC: Engine Warnings -- Undefined array index From: rowan.collins@gmail.com (Rowan Tommins) On 13/12/2022 10:11, Craig Francis wrote: > undefined indexes are a classic, but once you've found them all (the tricky bit), it often makes your code better, and helps identify mistakes (similar to undefined variables). > [...] > The null value can come from many sources (e.g. GET/POST/COOKIE/databases) These two examples are interesting in conjunction: $_GET, $_POST, and $_COOKIE will never contain null values unless you have code writing directly to them, because HTTP has no representation for it, only empty strings. So the only context where you'll get a null from them is because you mishandled an undefined array key, which as you say is often an indicator of a mistake. Data retrieved from a database is probably the most common source of actual null values. Sometimes, it's important to distinguish those nulls from empty strings, sometimes you don't care - but that's true of undefined array keys as well. Which is ultimately the problem with all of these discussions - some people will see more benefits from catching extra mistakes, others will see more cost from fixing code that's lazy but not actually broken. An interesting example I came across recently was a user-defined function for SQL string escaping (I'd like to stress legacy; I know that proper parameters avoid this issue). The function always expected a string, but didn't check that, so if given a PHP null, it would put '' in the SQL rather than NULL, leading to data corruption. I have effectively added the same notice to it as PHP has to built-in functions, to track down where else this might be causing problems without escalating to an error immediately. Regards, -- Rowan Tommins [IMSoP]