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); var_dump($b instanceof Foo); echo "instanceof Bar\n";
var_dump($a instanceof Bar); var_dump($b instanceof Bar); echo "subclass of Foo\n";
var_dump(is_subclass_of($a, 'Foo')); var_dump(is_subclass_of($b, 'Foo')); echo "subclass of Bar\n";
var_dump(is_subclass_of($a, 'Bar')); var_dump(is_subclass_of($b, 'Bar')); ?>
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)