Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117121 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 61292 invoked from network); 23 Feb 2022 12:40:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Feb 2022 12:40:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 38F2E1804F8 for ; Wed, 23 Feb 2022 05:59:59 -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-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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, 23 Feb 2022 05:59:58 -0800 (PST) Received: by mail-yb1-f174.google.com with SMTP id p19so48138223ybc.6 for ; Wed, 23 Feb 2022 05:59:58 -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=mET69021+8DCZxvF+2j+0XaRgzQXQwXzz16+1goa2Ac=; b=AD8evx2LH2QBguTZaCpJNuMP5k684LcdRtR+V5fmtDY8iL+/mItfeid0bXypzouSt8 crdCElLw+GxD/nzgWbD58JM6fwJ6ZJEMSnnru+HF1bgbPQJbTDdAB1Teoa0AeRTutTiA V+6+BWWJLKh8n+T+TsR2UfIifCA3olAV3hoSQe+cedP5w0qi15yDHzrGxlQMEyvjm1Ek JklaJQOZ0jAG3pIQtHYKBPCSk9PI+07kpj2A58CqjGDviQd/IybQ+m0hJ4y0tJB5iiIQ Nbc5q+pLZMkVRzDVbDRiTrzYXoXvBYf3vK5WAHuBQuvBeNEEz1KuzmlKBC352ITce0N1 qU9A== 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=mET69021+8DCZxvF+2j+0XaRgzQXQwXzz16+1goa2Ac=; b=Zb7+neECkE4+SqicgVu1mLKHO7tiIDkv7GYDs5HCframWtnBQz+t1AGfP9rQwKpEXN dR5GhgRESu77s1+NPci+S3L7uUJYat47IcnaFLKbaHikKqldHPXdIiTHJyvUnqF3kbbP yz+UywnO9OnrbSXBd+SzbCnTB+a2FpeeY9+sqxcrfZg25wdS8TYJUiTJdyBZqnEDy3zO FWsYxOEYYyx0l85PBpXFtJccz37G+IMhwQr2NAdqpCHyqcV+4tPa+PK/6PTcj4XktQRa 1kmuC9jMj6jt9+lBPRPHHw7J9sCGo44ENsxpUWtrfaLZ1RA1qqAYOtyTCYIaALvu7z2M UBBg== X-Gm-Message-State: AOAM530J540RYSC/1qqBHkcgg9G56YnGj7yeFKvirky88gRIWMzONqMN jOD9RXfFCt4svsoybUBytkia8RxATb+qhVzu7qMHMqFVIA== X-Google-Smtp-Source: ABdhPJwsBrBHOJG1e/GOgvRHnQtT7SKGtsdtvxCyG9gvzNy9ksgw/C2DCIMQ5Gc6aQ0RAyVYCaDzEhMXotzhLxmgmi0= X-Received: by 2002:a25:424b:0:b0:622:9567:24b8 with SMTP id p72-20020a25424b000000b00622956724b8mr27852616yba.156.1645624798128; Wed, 23 Feb 2022 05:59:58 -0800 (PST) MIME-Version: 1.0 References: <983552d8-11f1-b5bc-fb82-148347982fda@gmx.de> In-Reply-To: Date: Wed, 23 Feb 2022 14:59:46 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000086af1b05d8afe1f5" Subject: Re: [PHP-DEV] Allowing NULL for some internal functions From: guilliam.xavier@gmail.com (Guilliam Xavier) --00000000000086af1b05d8afe1f5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 22, 2022 at 3:59 AM Alexandru P=C4=83tr=C4=83nescu wrote: > 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=3D1` does not need to make loads of hard-to-find/unnecess= ary > > 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 =3D 0. > For history: https://wiki.php.net/rfc/scalar_type_hints_v5#behaviour_of_weak_type_checks (**emphasis** mine): > A weakly type-checked call to an extension or built-in PHP function has exactly the same behaviour as it did in previous PHP versions. > > The weak type checking rules for the new scalar type declarations are **mostly** the same as those of extension and built-in PHP functions. The only **exception** to this is the handling of `NULL`: in order to be **consistent with our existing type declarations for classes, callables and arrays**, `NULL` is not accepted by default (...) In hindsight, maybe that wasn't the most "fortunate" decision... (although, fair enough, `NULL` was never considered to be "scalar") > > In my view, false would have the same problem for those internal function= s. > Why should it be coerced to an empty string? > https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg#proposal i= s > 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. > > (...) > > 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 happenin= g > right now: > - int as 0, > - float as 0.0, > - string as an empty string > - bool as false. > Indeed, that could also be a way to solve the original (PHP 7.0) inconsistency between internal and user-defined functions (although PHP 8.1 started to take the opposite route...) > > I don't like it and I have no good idea how that would work as it would b= e > 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 rathe= r > 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 coerci= on > when strict_types=3D0 directive is explicitly defined as it would not cha= nge > anymore in PHP 9. > Or maybe (if going directly from error to implicit coercion is deemed too "risky") the current TypeError in non-strict_types mode (when passing NULL to a user-defined function expecting a scalar) could first be "demoted" to some kind of Notice [who said E_STRICT] in 8.2 (along with reverting the Deprecation added in 8.1 for internal functions) and removed in 9.0? --=20 Guilliam Xavier --00000000000086af1b05d8afe1f5--