Classes, instances and NULL

From: Date: Thu, 29 Jul 2004 12:41:57 +0000
Subject: Classes, instances and NULL
Groups: php.general 
Request: Send a blank email to php-general+get-192179@lists.php.net to get a copy of this message
Hi all, I have stumbled across something odd related to classes, instances and NULL in PHP 4. Apparently, an instance of a class that doesn't contain any variables is always equal to NULL. class MyClass { function anyFunction() { ... } } $c = new MyClass(); if ($c == null) { print "is \$c really null?"; } is_null($c)' however, returns false', as one would expect. As soon as the class contains a variable, the `$c == null' comparison returns false. Is there any logical reason why the comparison with the `==' operator returns `true'? I don't know about the internals of PHP, but I think this might be related to implementation details (e.g. instances of classes being associative arrays). However, from an OOP point of view this behaviour seems rather weird. I may not be the first to notice this. I couldn't find anything in the mailing list, if there has already been a discussion about this, just point me to the right direction. Thanks Oliver

« previous php.general (#192179) next »