Re: R: [PHP-DEV] [RFC] Deprecate passing null to non-nullableargumentsof internal functions
| From: | Christoph M. Becker | Date: | Wed, 02 Dec 2020 16:52:15 +0000 |
| Subject: | Re: R: [PHP-DEV] [RFC] Deprecate passing null to non-nullableargumentsof internal functions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112376@lists.php.net to get a copy of this message | ||
On 02.12.2020 at 17:34, Silvio Sparapano wrote:
> Hello,
> IMHO it’s only a declaration issue.
>
> In other terms, if documentation of strlen says:
>
> strlen ( string $string ) : int
>
> then I mean that $string MUST be a string, and return value MUST be an int.
>
> But then we found that if $string is null, zero is returned. If $string is an array, null is
> returned …
> We simply need consistency between how a function is documented, and how it really works.
> I mean, it may also be convenient for strlen to accept a parameter type other than string (such
> as null), but it must be well documented.
It is reasonably well documented:
| If the parameters given to a function are not what it expects, such as
| passing an array where a string is expected, the return value of the
| function is undefined. In this case it will likely return NULL but
| this is just a convention, and cannot be relied upon.
[1] <https://www.php.net/manual/en/functions.internal.php>
Regards,
Christoph