From: Nikita Popov Date: Tue, 19 Dec 2017 21:16:45 +0000 (+0100) Subject: Return false for instanceof on literal X-Git-Tag: php-7.3.0alpha1~706^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b6131364f95af68159b1c17ab48f9523e439cb65;p=php Return false for instanceof on literal --- diff --git a/Zend/tests/errmsg_041.phpt b/Zend/tests/errmsg_041.phpt deleted file mode 100644 index bfcafd261d..0000000000 --- a/Zend/tests/errmsg_041.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -errmsg: instanceof expects an object instance, constant given ---FILE-- - ---EXPECTF-- -Fatal error: instanceof expects an object instance, constant given in %s on line %d diff --git a/Zend/tests/instanceof_const.phpt b/Zend/tests/instanceof_const.phpt new file mode 100644 index 0000000000..f662d91603 --- /dev/null +++ b/Zend/tests/instanceof_const.phpt @@ -0,0 +1,10 @@ +--TEST-- +Instanceof on literals returns false +--FILE-- + +--EXPECT-- +bool(false) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index a032188e11..63f9d57e76 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7463,8 +7463,10 @@ void zend_compile_instanceof(znode *result, zend_ast *ast) /* {{{ */ zend_compile_expr(&obj_node, obj_ast); if (obj_node.op_type == IS_CONST) { - zend_error_noreturn(E_COMPILE_ERROR, - "instanceof expects an object instance, constant given"); + zend_do_free(&obj_node); + result->op_type = IS_CONST; + ZVAL_FALSE(&result->u.constant); + return; } zend_compile_class_ref_ex(&class_node, class_ast,