Odd PHP Logic
PHP 4 has weird logics. Consider the following code sample:
class MyClass {
function doIt() {
print "OK";
}
}
A class called MyClass is declared. This class contains a method called doIt.
Usually, in every other object oriented programming language I know, an instance of MyClass is something, i.e. it is an instance of a class. In PHP 4, however, against all logics of OOP, every instance of MyClass is null! The following excerpt prints the value 1:
$c = new MyClass(); print $c == null;
If the function is_null is used, however, PHP thinks that an instance of our class is not null. The following excerpt doesn't print anything:
if (is_null($c)) {
print "this variable is null";
}
If the class contains at least one variable (i.e. a line var $x;) PHP behaves as everybody with a minimal sense of logic could expect.
Disclaimer: This information is provided "as is", with absolutely no warranty expressed or implied. Any use is at your own risk.