note 89078 added to function.is-null
| From: | fuzzystudio at gmail dot com | Date: | Fri, 20 Feb 2009 16:17:18 +0000 |
| Subject: | note 89078 added to function.is-null | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150895@lists.php.net to get a copy of this message | ||
If you want to test if a class is null or not, always use is_null($class) instead of "$class ==
null". If the class instance has no members, then "$class == null" will be true.
Here is an example:
class ClassA
{
function printSomething()
{
print('Something');
}
}
class ClassB
{
var $doNothing;
function ClassB()
{
$this->doNothing = 'Nothing';
}
function printSomething()
{
print('Something');
}
}
$a = new ClassA();
print('<br> #1: ' . ($a == null ? '$a is null' : '$a is not
null'));
print('<br> #2: ' . (is_null($a) ? '$a is null' : '$a is not
null'));
$b = new ClassB();
print('<br> #3: ' . ($b == null ? '$b is null' : '$b is not
null'));
print('<br> #4: ' . (is_null($b) ? '$b is null' : '$b is not
null'));
The output of above is:
#1: $a is null
#2: $a is not null
#3: $b is not null
#4: $b is not null
----
Server IP: 87.124.35.190
Probable Submitter: 80.177.30.147
----
Manual Page -- http://www.php.net/manual/en/function.is-null.php
Edit -- https://master.php.net/note/edit/89078
Del: integrated -- https://master.php.net/note/delete/89078/integrated
Del: useless -- https://master.php.net/note/delete/89078/useless
Del: bad code -- https://master.php.net/note/delete/89078/bad+code
Del: spam -- https://master.php.net/note/delete/89078/spam
Del: non-english -- https://master.php.net/note/delete/89078/non-english
Del: in docs -- https://master.php.net/note/delete/89078/in+docs
Del: other reasons-- https://master.php.net/note/delete/89078
Reject -- https://master.php.net/note/reject/89078
Search -- https://master.php.net/manage/user-notes.php