Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117227 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26043 invoked from network); 2 Mar 2022 20:20:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Mar 2022 20:20:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B2C7C180539 for ; Wed, 2 Mar 2022 13:42:22 -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: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.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 ; Wed, 2 Mar 2022 13:42:22 -0800 (PST) Received: by mail-ej1-f48.google.com with SMTP id r13so6585432ejd.5 for ; Wed, 02 Mar 2022 13:42:22 -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=BNocoK+SEZfStiIDA8+fDIhE6jiif9FXWmKblGJg7Uc=; b=WMxESoTtOfk/6OWPJv+KoNiSpIiDpFQ8cLvzfD9I25yai9uNYIve7aDPQ7buhCgcVZ ZGz+UOK5DDE6cTCIWPQ6RPmsyqxTqJJUj/OihBLgCv6903GSHAu6C7q6F1d25pidYu1N fcLasOZWevIrmPiZHzEg5mvdKGuc0+FWWEUqqS7h/UrysD1emSnqqmq1kitc1IPmEZ5h sTQXMhOyvN4yAGi3uX5Y9e8oFGlcZSNaI/c4MIGFwmX8OxJcg/+4TJvBM1yIRNlRKC/o wTcbi+MMipCyPNPGstNjeJOkhxznX7Vvp692XrIYk+uImbqg3cdM8SmZQ2Nc4wiUaF0H TbJQ== 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=BNocoK+SEZfStiIDA8+fDIhE6jiif9FXWmKblGJg7Uc=; b=v4ngTEwjYWuNdhTceLddlJtIM1IcJJjGL5MNR9ucUTSscs8fSD3sPXIWJ/BH0sk2CD j8O6EClKNdjvSIRfuVuJa18XJ0njC1ivsbE8NtD0WmHNo0CRX4+Gb2yr+Q714ZbW5NIF dHmyZYuXsXZHkZ3drvEMHDCxkaODC6VDugMjX0lRDvRSdjGAsM/jX86G5tyU+kPI1nbP v1hFQS9Z/7lXXdCQFXGpMcUTuf6r/o78yf/VVxcEl+zIs+oFGtcRTntZJAOR3pk7gazA aIildswqTf4ArkQ7nQ3LcR1d2oAqOTq6xTYl7QkGti0Vrm3ps6koALNEW/iKSfIbo1VY AZ3g== X-Gm-Message-State: AOAM531bIzxK70sIevho9vVQwPYLKWyxk7Qo/eFvAtpgqun6DHj4WYWe EXNHvGmOjdRy5hsyLg+v0yTX0NQtIpXiHJKbE+QBJtaguQvobVUA X-Google-Smtp-Source: ABdhPJyX47RP/kOFxVeFFhx10rKmvlFeMSzLxFs9vUIj0WKmFhi3sDa8lIl6n/qP46Yu/ctswws11EpT3aRt+cDfd0g= X-Received: by 2002:a17:907:3da3:b0:6d8:2833:3baf with SMTP id he35-20020a1709073da300b006d828333bafmr5297955ejc.289.1646257340730; Wed, 02 Mar 2022 13:42:20 -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> <4bff3f23-a3ec-4416-f44e-1f4f5d7e0caa@gmail.com> <2d06bc12-7d7e-4a88-b823-de64642381e6@www.fastmail.com> In-Reply-To: <2d06bc12-7d7e-4a88-b823-de64642381e6@www.fastmail.com> Date: Wed, 2 Mar 2022 23:42:03 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000000d18e05d9432859" Subject: Re: [PHP-DEV] Allowing NULL for some internal functions From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --00000000000000d18e05d9432859 Content-Type: text/plain; charset="UTF-8" On Wed, Mar 2, 2022 at 4:17 PM Larry Garfield wrote: > On Wed, Mar 2, 2022, at 8:00 AM, Craig Francis wrote: > > On Wed, 2 Mar 2022 at 12:26, Dik Takken wrote: > > > >> So, to get this crystal clear, this is my understanding of what you are > >> proposing for passing null to a non-nullable function parameter > >> (hopefully my ASCII art will come through ok): > >> > >> > >> which | strict_types | PHP 8.0 | PHP 8.1 | PHP 9 > >> ----------|---------------|------------|------------|---------- > >> user | 1 | TypeError | TypeError | TypeError > >> internal | 1 | TypeError | TypeError | TypeError > >> user | 0 | TypeError | TypeError | coerced > >> internal | 0 | coerced | Deprecated | coerced > >> > >> Is this correct? > >> > > > > > > Yes, that's correct... although I'd be doing this for 8.2, to avoid > > TypeError exceptions being introduced for non `strict_types` scripts in > 9.0. > > > > This is based on the feedback from the quiz and here; so type coercion > from > > NULL would continue to work, like coercion from the other variable types > > (string/int/float/bool). > > > > Craig > > Null is not an empty string. Null is not a string. Null is not 0. Null > is not an integer. > > The clear trend of the language is toward more type strictness. Going > back on that is a bad idea. Furthermore, increasing the delta between weak > and strict mode only serves to bifurcate the language and add one more > thing that people have to think about when they move from one file to > another; the language behaves differently depending on what file you're > in. That's already a cognitive overhead. Don't add to it. > > I am firmly -1 on weakening the type system, even if "weak mode". > This sounds like a good approach as well, not weakening the type system but, even more, it might be good to strengthen it, even if we are talking about strict_types=0. What bothers me a bit is why should strlen(false) be a valid method call but strlen(null) not so much. I think this is the inconsistency that should be fixed so the language would be easier to work with. And maybe the way to fix it is removing some coercions that happen right now and make little or no sense, strengthening the type system. The only coercion that is valid even with strict types: - int to float Coercions that should probably be kept as it makes sense in some cases: - int numeric string to int - float numeric string to float - int numeric string to float - int to string - float to string - bool to int - int to bool Coercions that should not be allowed, even if explicit type conversion should be still kept: - float or float numeric string to int (already deprecated in 8.1, not allowed starting with 9.0 by https://wiki.php.net/rfc/implicit-float-int-deprecate) - bool to string - string to bool - bool to float - float to bool Coercions that are already not working, even if explicit type conversion works and should continue to work: - non numeric string to int or float, starting with PHP 7.0 - not well formatted numeric string to int or float, starting with PHP 8.0 - null to int/float/bool/string, starting with PHP 7.0, if that can be considered a possible coercion I think that some RFC for deprecating some more cases would make the language a bit more consistent and reduce the coercion variation once we get to PHP 9.0 Alex --00000000000000d18e05d9432859--