From: Felipe Pena Date: Wed, 30 Jan 2008 10:27:28 +0000 (+0000) Subject: Fixed Bug#43926 (isInstance() isn't equivalent to instanceof operator) X-Git-Tag: RELEASE_1_3_1~222 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8452585fc8edd0d783f9df28fc7fa83313d8a496;p=php Fixed Bug#43926 (isInstance() isn't equivalent to instanceof operator) --- diff --git a/NEWS b/NEWS index 1bd1e391a6..c48c1d6cc0 100644 --- a/NEWS +++ b/NEWS @@ -240,6 +240,7 @@ PHP NEWS - Fixed PECL bug #11216 (crash in ZipArchive::addEmptyDir when a directory already exists). (Pierre) +- Fixed bug #43926 (isInstance() isn't equivalent to instanceof operator). (Marcus) - Fixed bug #42368 (Incorrect error message displayed by pg_escape_string). (Ilia) - Fixed bug #42365 (glob() crashes and/or accepts way too many flags). diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d491784600..f798475b45 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3402,7 +3402,7 @@ ZEND_METHOD(reflection_class, isInstance) return; } GET_REFLECTION_OBJECT_PTR(ce); - RETURN_BOOL(ce == Z_OBJCE_P(object)); + RETURN_BOOL(HAS_CLASS_ENTRY(*object) && instanceof_function(Z_OBJCE_P(object), ce)); } /* }}} */ diff --git a/ext/reflection/tests/bug43926.phpt b/ext/reflection/tests/bug43926.phpt new file mode 100644 index 0000000000..373f9f1ba3 --- /dev/null +++ b/ext/reflection/tests/bug43926.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug#43926 - isInstance() isn't equivalent to instanceof operator +--FILE-- +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"); + +?> +--EXPECT-- +Is? A true, instanceof: true +Is? C false, instanceof: false +Is? D true, instanceof: true +Is? E true, instanceof: true \ No newline at end of file