Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117638 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71808 invoked from network); 27 Apr 2022 15:59:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Apr 2022 15:59:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8A755180540 for ; Wed, 27 Apr 2022 10:34:40 -0700 (PDT) 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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 ; Wed, 27 Apr 2022 10:34:40 -0700 (PDT) Received: by mail-wr1-f43.google.com with SMTP id q23so3514204wra.1 for ; Wed, 27 Apr 2022 10:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=craigfrancis.co.uk; s=default; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VHK0l0tzBd0MXHH18uMigXIte71SNwt77HydyP+CEGI=; b=fzYLY98o31gs04+GgFiGkx9WUkl5oDR8WvjO1yFR7EjsHFPVMndQjQIPrzNrpjinN4 E/yfS7lr7S/8ny/OeTwvahoF+yK2n23+ua2UeBavi10EesyoW9i7INd6ovaZ3QlavvzE NXDe7LfTWyD/ZY75os+2y7D8WAtD0Pv/jFDy0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=VHK0l0tzBd0MXHH18uMigXIte71SNwt77HydyP+CEGI=; b=QrMVaWbO6pFL3aAzr+En0d5CQ2R6UMzimMxtsWgIQfadP0IQLYodOms2PAbDvakhLu dE8u+W0Rz8Q4imy75IaOVyhZL5mWZqFdn5/WvcqM4P0UzRCD7ObCD84650PhSbf66Wxv Zm0QKa8qXNvUhVaJkNY6IpnGbQ6Q77kjKZ6js/2Dxqs0cfHf4rhB3h7OQr9LGoDGY4Uw bb5QMTzCyVE2eaNInfPF8oKGkjd7SWASyFmi6fcAwgQlgcKFR+JWFR5JZssuG9mdGoxY 54qLeNS9XneBwWKoLpxl5vAV1nGBFMT7/bB73jjb5Hw5rf0nANzH/g25ORDf4BSq+h5l v1Hg== X-Gm-Message-State: AOAM533MYCHxBn5TpUVQQCT9JETtNOMvfNNZSdb9mBQYAWq1uRl6fU07 /mAq0Hkxj5l/Xf5Vj03Gx6FcySN6ibmihw== X-Google-Smtp-Source: ABdhPJx9Ceg3bfYYwhCkgBKp9w4jDjKUxkZI8ZJCzZo/E1ggRjDJzRvyNvzobd2xXZkcqwdVKU5hPQ== X-Received: by 2002:adf:e10e:0:b0:206:2d7:b4de with SMTP id t14-20020adfe10e000000b0020602d7b4demr22572093wrz.497.1651080878695; Wed, 27 Apr 2022 10:34:38 -0700 (PDT) Received: from smtpclient.apple ([94.173.138.98]) by smtp.gmail.com with ESMTPSA id r184-20020a1c2bc1000000b00392af6f0ab0sm2029835wmr.18.2022.04.27.10.34.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Apr 2022 10:34:37 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) In-Reply-To: Date: Wed, 27 Apr 2022 18:34:36 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <59030DB4-4E5E-4DF6-AD88-F3665355C467@craigfrancis.co.uk> References: <42D0A480-F262-4F72-9C4D-887762A8D800@gmail.com> <0b061f28-a087-efd3-8602-424ee03458e0@gmail.com> <7DB0A01F-04FB-420D-9025-E027E5DE02F7@craigfrancis.co.uk> <19b2d192-fc4a-4122-8a01-54316a50fc1e@www.fastmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3696.80.82.1.1) Subject: Re: [PHP-DEV] NULL Coercion Consistency From: craig@craigfrancis.co.uk (Craig Francis) On 26 Apr 2022, at 21:11, Rowan Tommins wrote: >=20 > On 26/04/2022 17:36, Guilliam Xavier wrote: >> function mt_rand(int $min =3D UNKNOWN, int $max =3D UNKNOWN): int = {} >>=20 >> documented with two signatures at >> https://www.php.net/manual/en/function.mt-rand.php >>=20 >> mt_rand(): int >> mt_rand(int $min, int $max): int >=20 >=20 > This is actually a really pertinent example: you might expect = mt_rand(null, null) to give the same behaviour as mt_rand(), but = actually it will always return 0, because it silently coerces to = mt_rand(0, 0). That's exactly the kind of unexpected behaviour type = checking aims to protect against. First, thanks Guilliam for the examples. And Rowan, I agree it's a good example, and I've added it to the Open = Issues. But I'm wondering, is it only one function? and assuming it's a problem, = could we use `Z_PARAM_LONG_OR_NULL()` and specifically throw an = exception when either parameter is NULL, like the `max < min` check? On = the basis that I'd rather have one extra check for this function, and = keep NULL coercion working everywhere else (i.e. where it's fine). As an aside, under the Future Scope: https://wiki.php.net/rfc/null_coercion_consistency#future_scope I'd noted some functions that could do with some similar changes, but = that's more about copying the example of `$separator` in `explode()` and = the =E2=80=9Ccannot be empty=E2=80=9D error, so NULL or an Empty String = is rejected (rather than just rejecting NULL). > There used to be a lot more functions with pseudo-defaults like this, = but a lot were made to accept null in PHP 8.0. e.g. = mb_convert_encoding('foo', 'ASCII', null) now acts like = mb_convert_encoding('foo', 'ASCII') and looks up a run-time default; but = in previous versions it acted as mb_convert_encoding('foo', 'ASCII', '') = which is not a valid call. Thanks, that's another good example, but I'm going to be a pain, and = would suggest that the specific function was correctly updated to work = with NULL (and anyone who did pass NULL to that argument, would have had = the "must specify at least one encoding" error). Craig