Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117111 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56480 invoked from network); 22 Feb 2022 01:39:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Feb 2022 01:39:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 194D41804D9 for ; Mon, 21 Feb 2022 18:58:54 -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,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: No X-Envelope-From: Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 ; Mon, 21 Feb 2022 18:58:53 -0800 (PST) Received: by mail-ed1-f53.google.com with SMTP id w3so33449990edu.8 for ; Mon, 21 Feb 2022 18:58:53 -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 :cc; bh=Q88FziEL3B+ErjiNDWOvJW20e/yXOC1uL5lnSZ0VgoI=; b=hBu9riNw1HUfgQhxuRb9enKh1yjKj01t2P/tOi2z9YN2UPALnmZQrno+z+Qa+Vdy5C dMOCg883N/s5/4iuITxU10tzTUYahHstoz4wh/sBrHPzcImHNfGTLEY628HmqQaWSAYd xGgkUHxRTzxR4PbNuX2/A1mcIEi+mz6i95T+EX19SUuQMwp7R34+UkoqL33sf6j7+Lm4 k13nnTPW6tPpwR63usHQQORIz0sbQg44q+oGnOOtIIjFIzVp5N9orMWgdg2dWrsnZefP FS8IU7LYKUtrDuqsffXzUvmeI5tS7McihAl1SqkEBsjV84WEZCMZeAszPa7LmocDGErg SjjA== 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:cc; bh=Q88FziEL3B+ErjiNDWOvJW20e/yXOC1uL5lnSZ0VgoI=; b=qDUUoKuuQVovQJhp3W3mBaxJ/h8qjYTlqrOLbt6OR4hLgmAu8srAIWoGpUeNJCBfem 9FY7H/qqG7DGxkZizAe3wMmISwVukLeeoH6+DP7NgcjHlVY8iDJWeooQMu6nSf/IrK6f L2vggFVnaugFSKXlF6gCkbraPDEfoKebgbF9ADcjZonB4TJ1PSX1BUHrZ4AsBoYoIkRS x4iMSZszd5YQO+XEjn4nKvMnwpBFQkviGcZmDAU01ZV9OAdOgX7QkqgcTGU2ZWfJVs2a RLeOxAJG9lDUsqWQo4/L+8IS0rjwJnRJk5iiKCTr2WvPnnw1gcptrvMfep28QaJHSs76 ewZw== X-Gm-Message-State: AOAM531712kiOxJ+wVXfLuVTOpLYFyrkrsSlmgpKa0lZ8TeyFRpvjuC3 lcMkqvsLw4gmrQt+6fgLdSaD3Vf5tSNu3K5ubo4= X-Google-Smtp-Source: ABdhPJw/RonpTEEOQqykpDAHa2HO2R+SDDkzKegskyIdn6MPG2MGvwdn5atTXHeFbtX5wzIwbPSBOeeGlRkEXxs/eUo= X-Received: by 2002:a50:c04c:0:b0:410:b929:d658 with SMTP id u12-20020a50c04c000000b00410b929d658mr24369319edd.5.1645498732161; Mon, 21 Feb 2022 18:58:52 -0800 (PST) MIME-Version: 1.0 References: <983552d8-11f1-b5bc-fb82-148347982fda@gmx.de> In-Reply-To: Date: Tue, 22 Feb 2022 04:58:35 +0200 Message-ID: To: Craig Francis Cc: "Christoph M. Becker" , PHP internals Content-Type: multipart/alternative; boundary="00000000000068acb705d89287c5" Subject: Re: [PHP-DEV] Allowing NULL for some internal functions From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --00000000000068acb705d89287c5 Content-Type: text/plain; charset="UTF-8" On Mon, Feb 21, 2022 at 5:32 PM Craig Francis wrote: > On Mon, 21 Feb 2022 at 09:04, Christoph M. Becker > wrote: > > > That "inconsistency" had been introduced with PHP 7.0.0, i.e. right when > > scalar type declarations have been introduced. Passing a null to a > > non-nullable parameter of a *userland* function throws a TypeError > > > > > Thanks Christoph, that's a good way of looking at it. > > Considering NULL has been passed to these internal function parameters for > years, for a variety of reasons, and PHP has coerced it into an empty > string, integer 0, float 0, or boolean false... I'm wondering if my RFC > should focus on matching that expectation, so anyone not using > `strict_types=1` does not need to make loads of hard-to-find/unnecessary > edits; that way NULL would be treated the same as the other variable types > (I appreciate arrays and objects don't get coerced, but I don't think > anyone expects them to). > Yes, exactly that. A few weeks ago when the issue was mentioned again I had to remember by trying on 3v4l myself that using null for a string parameter wasn't an automatically coerced case when strict_types = 0. In my view, false would have the same problem for those internal functions. Why should it be coerced to an empty string? https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg#proposal is all about removing the automatic coercion that was happening for null in the internal functions Planning that in PHP 9 the type interpretation for internal function will be done the same as for user defined functions. Consistency. Right now, if a parameter type is defined as string in an user function, no matter what strict_type is configured, it would still result in a TypeError when passing null. For internal functions, even if the parameter type is defined as string, null would be passed and a coercion would happen. As I mentioned, coercing false to int would be for me almost as bad as coercing null to int. But when types are not considered important I think it's worth pursuing extending the coercion from null to the 4 other types where it's happening right now: - int as 0, - float as 0.0, - string as an empty string - bool as false. I don't like it and I have no good idea how that would work as it would be a pretty big BC break. Maybe it would be easier to change strict_types to default to 1 in PHP 9 along with adding the null coercion for null when strict_types is 0 rather than inventing a new strict_types value like -1 that would allow null coercion as well. Starting with a notice in PHP 8.2 when the directive is not present might be an interesting starting point. And no more warning for implicit coercion when strict_types=0 directive is explicitly defined as it would not change anymore in PHP 9. Regards, Alex --00000000000068acb705d89287c5--