note 45053 added to language.operators.type
| From: | \\" LeoPedretti \ \ " | Date: | Tue, 24 Aug 2004 15:59:44 +0000 |
| Subject: | note 45053 added to language.operators.type | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75207@lists.php.net to get a copy of this message | ||
The instanceof operator also checks the interface tree. For example, the following code:
<?
interface Human {
public function say($var);
public function gender();
}
class man implements Human {
public function say($var) {
"Oh yeah, $var\n"
}
public function gender() {
return "male";
}
}
class woman implements Human {
public function say($var) {
"Oh dear, $var\n"
}
public function gender() {
return "female";
}
}
$m = new man;
$w = new woman;
if ($p instanceof Human) {
print "\$p is Human.\n";
} else {
print "\$p is not Human.\n";
}
print "\$m is of gender ".$m->gender()."\n";
if ($w instanceof Human) {
print "\$w is Human.\n";
} else {
print "\$w is not Human.\n";
}
print "\$w is of gender ".$w->gender()."\n";
?>
Will produce the output
$m is Human.
$m is of gender male
$w is Human.
$w is of gender female
----
Manual Page -- http://www.php.net/manual/en/language.operators.type.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45053
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45053&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45053&report=yes
Search -- http://master.php.net/manage/user-notes.php