|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-24 13:23 UTC] felipe@php.net
[2008-01-30 10:30 UTC] felipe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 20 20:00:02 2025 UTC |
Description: ------------ Says the documentation: "Note: $class = new ReflectionClass('Foo'); $class->isInstance($arg) is equivalent to $arg instanceof Foo or is_a($arg, 'Foo')." However, this isn't true because not is checked the parent class. Reproduce code: --------------- <?php class E { } class D extends E { } class A extends D { } class C extends A { } $ra = new ReflectionClass('A'); $rc = new ReflectionClass('C'); $rd = new ReflectionClass('D'); $re = new ReflectionClass('E'); $ca = $ra->newInstance(); $cc = $rc->newInstance(); $cd = $rd->newInstance(); $ce = $re->newInstance(); print("Is? A ". ($ra->isInstance($ca) ? 'true' : 'false') .", instanceof: ". (($ca instanceof A) ? 'true' : 'false') ."\n"); print("Is? C ". ($ra->isInstance($cc) ? 'true' : 'false') .", instanceof: ". (($ca instanceof C) ? 'true' : 'false') ."\n"); print("Is? D ". ($ra->isInstance($cd) ? 'true' : 'false') .", instanceof: ". (($ca instanceof D) ? 'true' : 'false') ."\n"); print("Is? E ". ($ra->isInstance($ce) ? 'true' : 'false') .", instanceof: ". (($ca instanceof E) ? 'true' : 'false') ."\n"); ?> Expected result: ---------------- Is? A true, instanceof: true Is? C false, instanceof: false Is? D true, instanceof: true Is? E true, instanceof: true Actual result: -------------- Is? A true, instanceof: true Is? C false, instanceof: false Is? D false, instanceof: true Is? E false, instanceof: true