Re: NULL Coercion Consistency

From: Date: Sun, 08 May 2022 10:48:21 +0000
Subject: Re: NULL Coercion Consistency
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-117696@lists.php.net to get a copy of this message
On Sat, May 7, 2022 at 11:53 PM Aleksander Machniak <alec@alec.pl> wrote: > > What happens if you pass FALSE to such an argument? int(0). The same > would happen with NULL. > > The thing that everyone seems to be glossing over with these coercion examples is that in order to have any scalar value, it must be explicitly set *somewhere*. That might be inside an internal function with a pass-by-ref, it might be on a regular old assignment line, it might be as the result of a function return... but somewhere the scalar must be set to that variable. This is not the case with null. If you use the unset() function on a variable for example, it will var_dump as null *and* it will pass an is_null() check *and* it will pass a $var === null *and* it will return false for an isset() check. Null loses these qualities if it is cast to *any* scalar. See: https://3v4l.org/lUcVV False being cast to int(0) at least doesn't change whether or not it will return true or false for isset(). Null fundamentally has the meaning that a variable is uninitialized, no matter what other ways a program happens to use it. Jordan

« previous php.internals (#117696) next »