note 31759 added to function.is-object
| From: | lbjay at rack1 dot php dot net | Date: | Fri, 02 May 2003 17:18:49 +0000 |
| Subject: | note 31759 added to function.is-object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47391@lists.php.net to get a copy of this message | ||
I'm not even sure how to articulate this, so I'm going to just include test code. Maybe
someone else will someday wonder the same thing.
<?
error_reporting(E_ALL);
class testParent
{
var $child;
function testParent()
{
$this->child = new testChild();
}
}
class testChild
{
function testChild()
{
}
}
$parent = new testParent();
$parent2 = 'foobar';
print join(',', Array(
is_object($parent) ? 'yes' : 'no',
is_object($parent->child) ? 'yes' : 'no',
is_object($parent2) ? 'yes' : 'no',
is_object($parent2->child) ? 'yes' : 'no'
));
?>
This prints "yes,yes,no,no". Basically this shows that you can use is_object to test if
the child object is an object without worrying about an error if the parent object isn't an
object either.
--
http://www.php.net/manual/en/function.is-object.php
http://master.php.net/manage/user-notes.php?action=edit+31759
http://master.php.net/manage/user-notes.php?action=delete+31759
http://master.php.net/manage/user-notes.php?action=reject+31759