com php-src: Delay array to string conversion notice until runtime: Zend/tests/runtime_compile_time_binary_operands.phpt Zend/zend_compile.c
| From: | Bob Weinand | Date: | Wed, 27 Feb 2019 17:46:31 +0000 |
| Subject: | com php-src: Delay array to string conversion notice until runtime: Zend/tests/runtime_compile_time_binary_operands.phpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104873@lists.php.net to get a copy of this message | ||
Commit: 94d3e4010217a19b0d0e44099b8a075aec307c0f
Author: Bob Weinand <bobwei9@hotmail.com> Wed, 27 Feb 2019 18:46:31 +0100
Parents: a72c74162491f20685ef6805af432717cbcffe90
Branches: PHP-7.4
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=94d3e4010217a19b0d0e44099b8a075aec307c0f
Log:
Delay array to string conversion notice until runtime
Changed paths:
M Zend/tests/runtime_compile_time_binary_operands.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/runtime_compile_time_binary_operands.phpt
b/Zend/tests/runtime_compile_time_binary_operands.phpt
index 91eb792..31366cd 100644
--- a/Zend/tests/runtime_compile_time_binary_operands.phpt
+++ b/Zend/tests/runtime_compile_time_binary_operands.phpt
@@ -148,7 +148,7 @@ if($c === 0) {
===DONE===
--CLEAN--
<?php
-$fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'compare_equality_temp.php';
+$fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'compare_binary_operands_temp.php';
@unlink($fl);
?>
--EXPECTF--
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 75ced7c..9bf70d8 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -6814,6 +6814,16 @@ ZEND_API zend_bool zend_binary_op_produces_numeric_string_error(uint32_t
opcode,
}
/* }}} */
+ZEND_API zend_bool zend_binary_op_produces_array_conversion_error(uint32_t opcode, zval *op1, zval
*op2) /* {{{ */
+{
+ if (opcode == ZEND_CONCAT && (Z_TYPE_P(op1) == IS_ARRAY || Z_TYPE_P(op2) == IS_ARRAY)) {
+ return 1;
+ }
+
+ return 0;
+}
+/* }}} */
+
static inline zend_bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode, zval *op1, zval
*op2) /* {{{ */
{
binary_op_type fn = get_binary_op(opcode);
@@ -6831,6 +6841,10 @@ static inline zend_bool zend_try_ct_eval_binary_op(zval *result, uint32_t
opcode
if (zend_binary_op_produces_numeric_string_error(opcode, op1, op2)) {
return 0;
}
+ /* don't evaluate array to string conversions at compile-time */
+ if (zend_binary_op_produces_array_conversion_error(opcode, op1, op2)) {
+ return 0;
+ }
fn(result, op1, op2);
return 1;
@@ -7000,10 +7014,18 @@ void zend_compile_binary_op(znode *result, zend_ast *ast) /* {{{ */
if (opcode == ZEND_CONCAT) {
/* convert constant operands to strings at compile-time */
if (left_node.op_type == IS_CONST) {
- convert_to_string(&left_node.u.constant);
+ if (Z_TYPE(left_node.u.constant) == IS_ARRAY) {
+ zend_emit_op_tmp(&left_node, ZEND_CAST, &left_node, NULL)->extended_value =
IS_STRING;
+ } else {
+ convert_to_string(&left_node.u.constant);
+ }
}
if (right_node.op_type == IS_CONST) {
- convert_to_string(&right_node.u.constant);
+ if (Z_TYPE(right_node.u.constant) == IS_ARRAY) {
+ zend_emit_op_tmp(&right_node, ZEND_CAST, &right_node, NULL)->extended_value =
IS_STRING;
+ } else {
+ convert_to_string(&right_node.u.constant);
+ }
}
if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
opcode = ZEND_FAST_CONCAT;