note 109108 added to internals2.opcodes.instanceof

From: Date: Wed, 20 Jun 2012 18:54:53 +0000
Subject: note 109108 added to internals2.opcodes.instanceof
Groups: php.notes 
Request: Send a blank email to php-notes+get-188726@lists.php.net to get a copy of this message
When checking instanceof against a subclass of the class in question, it will return true. <?php class Foo { public $foobar = 'Foo'; public function test() { echo $this->foobar . "\n"; } } class Bar extends Foo { public $foobar = 'Bar'; } $a = new Foo(); $b = new Bar(); echo "use of test() method\n"; $a->test(); $b->test(); echo "instanceof Foo\n"; var_dump($a instanceof Foo); // TRUE var_dump($b instanceof Foo); // TRUE echo "instanceof Bar\n"; var_dump($a instanceof Bar); // FALSE var_dump($b instanceof Bar); // TRUE echo "subclass of Foo\n"; var_dump(is_subclass_of($a, 'Foo')); // FALSE var_dump(is_subclass_of($b, 'Foo')); // TRUE echo "subclass of Bar\n"; var_dump(is_subclass_of($a, 'Bar')); // FALSE var_dump(is_subclass_of($b, 'Bar')); // FALSE ?> Result (CLI, 5.4.4): use of test() method Foo Bar instanceof Foo bool(true) bool(true) instanceof Bar bool(false) bool(true) subclass of Foo bool(false) bool(true) subclass of Bar bool(false) bool(false) ---- Server IP: 69.147.83.197 Probable Submitter: 63.119.10.10 ---- Manual Page -- http://www.php.net/manual/en/internals2.opcodes.instanceof.php Edit -- https://master.php.net/note/edit/109108 Del: integrated -- https://master.php.net/note/delete/109108/integrated Del: useless -- https://master.php.net/note/delete/109108/useless Del: bad code -- https://master.php.net/note/delete/109108/bad+code Del: spam -- https://master.php.net/note/delete/109108/spam Del: non-english -- https://master.php.net/note/delete/109108/non-english Del: in docs -- https://master.php.net/note/delete/109108/in+docs Del: other reasons-- https://master.php.net/note/delete/109108 Reject -- https://master.php.net/note/reject/109108 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188726) next »