]> granicus.if.org Git - php/commitdiff
Generate ZEND_COUNT for sizeof()
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 11 Apr 2019 08:48:52 +0000 (10:48 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 11 Apr 2019 08:48:52 +0000 (10:48 +0200)
sizeof() is an alias of count(), so we should generate the same
code for them.

Zend/zend_compile.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

index 2fa847d180d6c92cdd5a715ed4093d6a2daa08ef..ccdbd8a1b7699b2a011eb498284133e266bd494c 100644 (file)
@@ -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")) {
index 0f74e4280e684b393a1078117bf372fc2e2b39aa..d71694223f86b054ceb32bf185ed0156404304ac 100644 (file)
@@ -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);
index 05c6101bcc09f6bae3bfe14ac75a42f09f1d5bb8..7977a2a4a0b59ea0552a1a36da7bef1a7ee4b07a 100644 (file)
@@ -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);