com php-src: Return false for instanceof on literal: Zend/tests/errmsg_041.phpt Zend/tests/instanceof_ const.phpt Zend/zend_compile.c
| From: | Xinchen Hui | Date: | Tue, 19 Dec 2017 21:16:45 +0000 |
| Subject: | com php-src: Return false for instanceof on literal: Zend/tests/errmsg_041.phpt Zend/tests/instanceof_ const.phpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100784@lists.php.net to get a copy of this message | ||
Commit: b6131364f95af68159b1c17ab48f9523e439cb65
Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 19 Dec 2017 22:16:45 +0100
Parents: fc46c4b1061f54246a754dd7a32a41902062e652
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b6131364f95af68159b1c17ab48f9523e439cb65
Log:
Return false for instanceof on literal
Changed paths:
D Zend/tests/errmsg_041.phpt
A Zend/tests/instanceof_const.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/errmsg_041.phpt b/Zend/tests/errmsg_041.phpt
deleted file mode 100644
index bfcafd2..0000000
--- a/Zend/tests/errmsg_041.phpt
+++ /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
index 0000000..f662d91
--- /dev/null
+++ b/Zend/tests/instanceof_const.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Instanceof on literals returns false
+--FILE--
+<?php
+
+var_dump("abc" instanceof stdclass);
+
+?>
+--EXPECT--
+bool(false)
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index a032188..63f9d57 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,