Re: Classes, instances and NULL
| From: | Mehdi Achour | Date: | Thu, 29 Jul 2004 13:07:57 +0000 |
| Subject: | Re: Classes, instances and NULL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-192184@lists.php.net to get a copy of this message | ||
Hi Oliver, you should test with === instead of ==
http://php.net/manual/en/language.operators.comparison.php
didou
Oliver Hitz wrote:
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, returnsfalse', 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