Curt Zirzow wrote:


This also leads me to believe that the statement:

if ($var === null) {}

would be considered illegal or  fail no matter what since null is
not a value and has no type associated with it.

Of course, it doesn't fail, because null is a value:


<?php
$a = null;
var_dump($a === null);
?>

Try that. you get "true"

null is a value that represents nothingness, kind of a variable equivalent of the number 0. I know there's been lots of blather about whether null is a value on an intellectual level, but if it wasn't a value, you couldn't assign it to a variable. That's how programming languages work. int is a type, for example. You can't do this:

$a = int;

You can do:

$a = (int) $b;

null is not a type. You can do:

$a = null;

but can't do:

$a = (null) $b;

You have to use the type unset:

$a = (unset) $b;

So, null is a value of type unset in the way that PHP has been designed. The odd thing is that unset() can't be used to create a variable of type unset, the way array() is used to create a variable of type array - this is the only inconsistency.

<?php
$a = null;
var_dump(is_null($a)); // doesn't throw a warning
unset($a);
var_dump(is_null($a)); // throws a warning
?>

It doesn't matter much what people think about it, PHP has implemented null as a value, and I actually find that quite useful. It helps to represent the difference between 0 and '' and NULL returned from a database query (yes, mysql supports all three), and also is useful in specifying default values for parameters to a function that can also accept boolean false.

Greg


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to