]> granicus.if.org Git - php/commitdiff
Return false for instanceof on literal
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 19 Dec 2017 21:16:45 +0000 (22:16 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 19 Dec 2017 21:16:45 +0000 (22:16 +0100)
Zend/tests/errmsg_041.phpt [deleted file]
Zend/tests/instanceof_const.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/errmsg_041.phpt b/Zend/tests/errmsg_041.phpt
deleted file mode 100644 (file)
index bfcafd2..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
---TEST--
-errmsg: instanceof expects an object instance, constant given
---FILE--
-<?php
-
-var_dump("abc" instanceof stdclass);
-
-echo "Done\n";
-?>
---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 (file)
index 0000000..f662d91
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Instanceof on literals returns false
+--FILE--
+<?php
+
+var_dump("abc" instanceof stdclass);
+
+?>
+--EXPECT--
+bool(false)
index a032188e11fc2e7ca7ec8f244fc246190f8c17c9..63f9d57e76437de071c2681674ed4d4a4e492d2e 100644 (file)
@@ -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,