Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117179 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 84859 invoked from network); 1 Mar 2022 12:51:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Mar 2022 12:51:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6C19C180505 for ; Tue, 1 Mar 2022 06:12:46 -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.8 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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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, 1 Mar 2022 06:12:46 -0800 (PST) Received: by mail-qv1-f43.google.com with SMTP id b12so1172776qvk.1 for ; Tue, 01 Mar 2022 06:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=TKdm6r5NbNgLAbYs8gwpgCXX93eHJvob2mtJynTHAXk=; b=l/wYskgzVqIqGibZfaKGPUcjrCkgzJ/bU6Y8xnVgpWoPiE/oDmINKwx4IZukwAjgbS iPLaWuulEUI4IPArLQTnzpLbG36bVRgumtUyXEagBKGWT+Ls8/NZAQG9YoIv6rbgfOUx cr05lcvNmFhk6Iv92O+LuKJ1Dy41dzahpradT0tBqMpsVHu95caaF78HuNNf/wlvkJXq Q6xDLB5E79KCvEggMXOtvlRQKVW86irdlePiPnUf8kdv+yz9L3jHjsu//eaQUAh46pRG ygnciKUcgW3n4qzfqwRCBQZN7Ym5ZwQeQCXXCAfkqexkhZEBubn1yNV5JYi5sRQqPkVl wNkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=TKdm6r5NbNgLAbYs8gwpgCXX93eHJvob2mtJynTHAXk=; b=dYb51NnnvlJCu5HwW9TxzGiBPYTcehcBwTblSPRGrID5KwjL/93jRx6PAUkOcHmtpM wpdSb2w5jQdYJ1RoXdOHpnnon8H4uJim6aSKgCw+cmEuqIEn+7D0YX5LgLmNUszQjY8F yq5bQsT6UIBCBRYHLmQEurXLu7If67hn6qU/6vwYfoZkKk0iTyYDi8kZQjMJ3kP/E7dG jCXdKp1NygGCHGOuIVkMoriMKZuY0fwYE+XLwy/EfI/PIUWhY8pRDMKaOvObu2G1guUK nQOtcW/DGOBEv/ZyPE/63munpqnGfSAl7bDmn/TDi880NcVQozj5dejLkT6R4bRr08oN +qog== X-Gm-Message-State: AOAM531nv+VelJj/zZI3iPPsvtwpzbwXHigHx/fj0XLkaaB4HTi1e54p DwKUibAf0bIJ8ZOn3zus0lRI7KHHTBXPkpHfsC08moaNkc8dcQ== X-Google-Smtp-Source: ABdhPJzL09j+7AHjyLPo84oMMyhrej3AiY8Au+Kt8grORY5ktqRAJ8/pGO6CCT48uaQq4qBLd/pKzRp7B2yMgB6VFMA= X-Received: by 2002:a05:6214:e88:b0:435:7ff:c307 with SMTP id hf8-20020a0562140e8800b0043507ffc307mr1576178qvb.31.1646143965006; Tue, 01 Mar 2022 06:12:45 -0800 (PST) MIME-Version: 1.0 References: <983552d8-11f1-b5bc-fb82-148347982fda@gmx.de> <5494eaa7-2fa6-8364-9683-a2c8c9789d81@gmail.com> <69642616-72b7-44fe-97a7-27ae03bc8fce@www.fastmail.com> <7fbed755-42e2-d023-285f-39863a97f297@gmx.de> <3665C848-B4C3-4528-AEFA-02C868748AA8@cschneid.com> <0b5bc29d-3814-0e1d-b94a-47790019c778@gmx.de> <5463E9FF-309D-4CFA-B709-81498B934059@cschneid.com> In-Reply-To: <5463E9FF-309D-4CFA-B709-81498B934059@cschneid.com> Date: Tue, 1 Mar 2022 14:12:35 +0000 Message-ID: To: php internals , Craig Francis Content-Type: multipart/alternative; boundary="000000000000488e2405d928c280" Subject: Re: [PHP-DEV] Allowing NULL for some internal functions From: tekiela246@gmail.com (Kamil Tekiela) --000000000000488e2405d928c280 Content-Type: text/plain; charset="UTF-8" Hi Craig, > No, there is an inconsistency which leads to a backwards compatibility issue, and I'm trying to fix it. Which inconsistency exactly do you have in mind? The discussion is about passing arguments to functions. We are not discussing type juggling or type casting. To clarify the whole thing let's list out the key points: - PHP has a concept of scalar types consisting of these four types: string, int, float, bool - PHP has type juggling that converts the value to the type required by the context in which it is used. The behaviour is defined for scalar types, but often undefined for other types (see juggling to array) - PHP lets users cast values to a specified type. There are 7 (+1) available casts in PHP (disregarding aliases). Casting to scalar types from scalar types is defined. Casting to scalar from other types is partially defined and causes undefined behaviour in some cases. Warnings are generated in certain situations (e.g. array to string) and fatal errors when the cast cannot be performed at all. - PHP has a special type called NULL with a single value NULL. It's not a scalar and it's not a stand-alone type. Casting to NULL is not possible. For all intents and purposes, NULL value represents a variable with no value. For this reason, converting to other types generally does not cause any notices, warnings or errors. However, using NULL might generate warnings or errors depending on an operation. e.g. `null[0]`, `null->scalar` or `[...null]` - PHP has a concept of strict typing. It applies only to scalar parameters. By default, PHP will coerce values of the wrong type into the expected scalar type declaration if possible. NULL being a non-scalar value doesn't coerce in non-strict mode. Neither does array, object or resource. See https://3v4l.org/WZdQC The only inconsistency is that PHP's internal functions silently accepted NULL values for non-nullable parameters. This will be addressed in PHP 9.0. Changing the signatures of some functions might be reasonable but, as few others have said, it's not the solution we want to see because it feels like a hack. As I have also pointed out off-list, in many cases making the parameter type nullable would not make any sense as passing null to certain functions is a clear bug. It would also have an impact on strict typing! We could also reclassify NULL as a scalar type but that would be a fundamental language change. It would likely be a bigger BC change than fixing the current inconsistency. By the way, your statement that "Coercion works for string/int/float/bool, *and* NULL." is invalid. Coercion is defined only for scalar types as I have explained above. Type juggling for most types from NULL is defined, but that is not what we are discussing. Regards, Kamil --000000000000488e2405d928c280--