Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117210 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85940 invoked from network); 2 Mar 2022 13:17:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Mar 2022 13:17:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3708718055D for ; Wed, 2 Mar 2022 06:39:29 -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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8560 212.227.0.0/16 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (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 06:39:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1646231966; bh=TV7q9gz5tI/Hqi56gZyl49K3hWlpteY1iNR8q22dQ7g=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=M/IdX+bnZQFu1V9VpumEvgpi5AXSYnpQfBXBS0i3affUIKffbZ76jHe2/2BZ0S9WN Mqg6s/W7exQ0uywsS88qUe3parY7JAPi9MKrBz2oKpFON7xCqvGxaEQP3rsVxL4FRq TgNh9tiek6qCsoACP0tquWc9FGx/+ZzexzKKtJk0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mlw7V-1o6USj1FEB-00j38t for ; Wed, 02 Mar 2022 15:39:26 +0100 Message-ID: Date: Wed, 2 Mar 2022 15:39:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: internals@lists.php.net 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> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:/Zok8uv1ecDUnIO0niM2RQTyuwBIPOHQjGGtfOLb39pr5gd1dnr FkXpN3LqERrNs0/WexdwCmqVjTeLka3TxKGboepSmBHKBZfMlI7pbhJZlDgpEDLHIkgjJMD xga0HuWPv3Z8jS2QuPcf0UOH56z/pAyJn4OSlEwD9yAmkKyjFe5stW6RJvawP5XnohRnxM1 V/LRux2cNJO4cqrR9NR2w== X-UI-Out-Filterresults: notjunk:1;V03:K0:OXPUXCsbTqY=:z5c51tzeJcUUqsPabN+Wso PTO9t9vyEk9mjfnJWMFjQGJQsG0/LkiiRK3s2tI4AAqlBeNJuP+NAyZoqpFpP9LPG8dJ4bgBr IftR0XeKLXo7XaOdj+Z7a41+vCXo1d53rRYdCnQuZLEK0vn6cxfstPB9z5RPaFPRQZ8uscFH8 2X+mpCWzji41hvjN1YA0uXQJfnGPxws+3mdN7GE0g1iwfqEF1psu2F5VCXblGRydJWC6FSlU3 A4xyYVxyfCegAZqI7a16cvF0HVuvTDzYJdBCWOdlGX/iygwFPAPimf23mPf7hD+pceE4IAsqE xOwimbPrCTtdhcbGJc/YgnhavyJ9Jd+mmkSpPBRX4+/5XEwF8cRRA7ToX4PSmT85VzrLYEngd ZM9eXGV1f4fCaAGJoK1Ua2jcceyVCKLzdURJnZYm0TCxRWVbnliVRUNMPga+iBJ+KUnCgA8F8 WmjteIKDpihmYE/ioGQ12nry0FnVG4dxmz6b4vtQvgvtUrzad2biEL0JiGsVvmYfCcE9+88nr IVc9sk4NDWuMuG3BULR+Tnb5fC58CHf/l7ncKqswP9pfWmwwBwMNBYJbNMNm8+fZgAKkCHv/+ Ku4i/5WiDhEjShASpAO6epG0v1nYQR0AeaJ+7T1OXUPSAHEQM40K9fF9x5gG7s/VMqNV0Jacn 5/9U5U6C05P5nw8F3TDkDavjvZJMLHdDHPRPkjZIVFh+nC4jd5WOSNMl1WtGeOarVPXoagAcf auhcnueqoRQSLlxJQXw7z6L2bNKSZruwOU5z9FCHPhz6bqy5xmUm36eDIR2jEwWykJFwpAAqM CHqwr+wibk+zCZUtSUdCaKlNtu2OgvOKDqqWHMEjIKE9y6z4sk6GVeGhKc/I8zglOdqFOyjUZ 3Ri7zsE3xB/eMmghgZfJ57jMpuqE8pQs9NHXpOda3lQZMqI6nEsV0r6i5Nro+rfuVUhD6pg3X IZn79sQnIYySt8WRah7u2fuGXKZ3U0q6P7KGjdPL1/jFAIS0CXfgymgLYlYGmf7Ux5XZuvzun S9bkwVeRLxezWrnYSEP6V+0TZvb4UiPM27a3nwc8hWGQyDtwL856vs6589TQZsupIxGa7Kd0h Cl0vhSDKedOIv0= Subject: Re: [PHP-DEV] Allowing NULL for some internal functions From: a.leathley@gmx.net (Andreas Leathley) On 02.03.22 15:00, 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 f= rom > NULL would continue to work, like coercion from the other variable types > (string/int/float/bool). Type coercion already often does not work - giving the string "s" to an integer-typed argument will lead to a TypeError, it will not be coerced. I would prefer less coercions rather than more. That you can give a bool-typed argument "s" and it will be coerced to true seems quite bad to me, for example. I am someone who never uses strict_types although I use types everywhere in my code - accepting the string "1" for an integer type seems fine to me, especially because with HTTP requests you always get strings, and often you also get strings from other external sources, like CSV, databases, etc. So type coercion from strings to a certain degree seems reasonable to me (although even there I am using more and more explicit casts), but having to coerce null seems always avoidable to me, and null is a special value explicitely. In my data null and an empty string sometimes are two possible values, and automatic conversion seems like a value judgement by the language that they are kind of similar, which they should not be.