Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116996 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52256 invoked from network); 7 Feb 2022 11:41:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Feb 2022 11:41:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9AA991804F8 for ; Mon, 7 Feb 2022 04:57:40 -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=-1.9 required=5.0 tests=BAYES_00,HTML_MESSAGE, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS1836 195.49.0.0/17 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (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, 7 Feb 2022 04:57:39 -0800 (PST) Received: from smtpclient.apple (unknown [IPv6:2a02:1210:2ea4:cf00:e073:c801:a295:2e80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 807F3151668F for ; Mon, 7 Feb 2022 13:57:37 +0100 (CET) Content-Type: multipart/alternative; boundary="Apple-Mail=_95E7DA14-AA98-456B-A9B4-0A98921F093D" Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.60.0.1.1\)) Date: Mon, 7 Feb 2022 13:57:37 +0100 References: <7CCE6061-F5BD-4C10-8BD1-F5A2A994D5F6@cschneid.com> To: internals In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3693.60.0.1.1) Subject: Re: [PHP-DEV] Allowing NULL for some internal functions From: cschneid@cschneid.com (Christian Schneider) --Apple-Mail=_95E7DA14-AA98-456B-A9B4-0A98921F093D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Am 07.02.2022 um 13:07 schrieb G. P. B. : > On Mon, 7 Feb 2022 at 09:34, Christian Schneider = > wrote: > > If a parameter expects a string, that is what it should be given, = and its the callers' responsibility to ensure that is the case. If they = fail to do so then it's an error just like any other. >=20 > The decision to define e.g. strlen() as strlen(string $string) instead = of strlen(?string $string) was arbitrary and I for one would prefer the = loose definition. >=20 > - Chris >=20 > I'm not sure what you are getting on here? strlen() was always defined = to only take a string and never was nullable in the first place. Now this is a little bit misleading: Before 7.0 we did not have scalar = type hints so the documentation of strlen(string $string) was somewhat = lying, especially because back in those days the automatic type jugging = from null to "" was used a lot. > The RFC which is at the heart of this is the one to make internal = functions and userland functions consistent. > Therefore introducing a mechanism which makes only *some* functions = special and weird is a complete no go for me. > Either there is a (strong) case for the parameter to be nullable, and = then it should be marked as such and not do weird shenanigans with = regards to strict_types (which I dislike more and more by the second), = or there is not. So you are basically saying that we should discuss making it strlen(?string $string): int which would be cleaner, I agree. About the case having to be strong: I could also argue that you have to = make a strong case on why null should not be allowed any more (any more = as per implementation, not documentation) as it is a seizable BC. There are other things which can go wrong with strlen() on a higher = level (e.g. misuse with utf-8) and I would like to see a real world code = where strlen(null) actually broke something while not generating any = other error in the code path. - Chris --Apple-Mail=_95E7DA14-AA98-456B-A9B4-0A98921F093D--