note 45053 deleted from language.operators.type by colder

From: Date: Sat, 24 Feb 2007 10:00:22 +0000
Subject: note 45053 deleted from language.operators.type by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123806@lists.php.net to get a copy of this message
Note Submitter: "Leo Pedretti" <lpedretti at suserver dot com> ---- 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

« previous php.notes (#123806) next »