summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-04-11 10:48:52 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-04-11 10:48:52 +0200
commit30df87f77d87d446afbfa4c9d2e0a1a643cc4bdc (patch)
treeaa3304a339354c468ec4cdaa94c49fe1be922ca6
parentb213f13a2621ec553beec06d3e2f163c1e7e2282 (diff)
downloadphp-git-30df87f77d87d446afbfa4c9d2e0a1a643cc4bdc.tar.gz
Generate ZEND_COUNT for sizeof()
sizeof() is an alias of count(), so we should generate the same code for them.
-rw-r--r--Zend/zend_compile.c12
-rw-r--r--Zend/zend_vm_def.h2
-rw-r--r--Zend/zend_vm_execute.h8
3 files changed, 13 insertions, 9 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 2fa847d180..ccdbd8a1b7 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3551,16 +3551,19 @@ static int zend_compile_func_in_array(znode *result, zend_ast_list *args) /* {{{
}
/* }}} */
-int zend_compile_func_count(znode *result, zend_ast_list *args) /* {{{ */
+int zend_compile_func_count(znode *result, zend_ast_list *args, zend_string *lcname) /* {{{ */
{
znode arg_node;
+ zend_op *opline;
if (args->children != 1) {
return FAILURE;
}
zend_compile_expr(&arg_node, args->child[0]);
- zend_emit_op_tmp(result, ZEND_COUNT, &arg_node, NULL);
+ opline = zend_emit_op_tmp(result, ZEND_COUNT, &arg_node, NULL);
+ opline->extended_value = zend_string_equals_literal(lcname, "sizeof");
+
return SUCCESS;
}
/* }}} */
@@ -3739,8 +3742,9 @@ int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_l
return zend_compile_func_cuf(result, args, lcname);
} else if (zend_string_equals_literal(lcname, "in_array")) {
return zend_compile_func_in_array(result, args);
- } else if (zend_string_equals_literal(lcname, "count")) {
- return zend_compile_func_count(result, args);
+ } else if (zend_string_equals_literal(lcname, "count")
+ || zend_string_equals_literal(lcname, "sizeof")) {
+ return zend_compile_func_count(result, args, lcname);
} else if (zend_string_equals_literal(lcname, "get_class")) {
return zend_compile_func_get_class(result, args);
} else if (zend_string_equals_literal(lcname, "get_called_class")) {
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 0f74e4280e..d71694223f 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -8379,7 +8379,7 @@ ZEND_VM_COLD_CONST_HANDLER(190, ZEND_COUNT, CONST|TMP|VAR|CV, UNUSED)
} else {
count = 1;
}
- zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
+ zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 05c6101bcc..7977a2a4a0 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -9588,7 +9588,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CONST_
} else {
count = 1;
}
- zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
+ zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);
@@ -20293,7 +20293,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_TMP_UNUSED_HANDLER(
} else {
count = 1;
}
- zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
+ zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);
@@ -29522,7 +29522,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_VAR_UNUSED_HANDLER(
} else {
count = 1;
}
- zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
+ zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);
@@ -50779,7 +50779,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_COUNT_SPEC_CV_UNUSED_HANDLER(Z
} else {
count = 1;
}
- zend_error(E_WARNING, "count(): Parameter must be an array or an object that implements Countable");
+ zend_error(E_WARNING, "%s(): Parameter must be an array or an object that implements Countable", opline->extended_value ? "sizeof" : "count");
} while (0);
ZVAL_LONG(EX_VAR(opline->result.var), count);