Skip to content

Commit 4ae6447

Browse files
committed
Another round of fixes
1 parent fd6ed9a commit 4ae6447

18 files changed

+52
-77
lines changed

Zend/tests/function_arguments/argument_count_incorrect_internal_strict.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ try {
2121
ArgumentCountError
2222
substr() expects at least 2 arguments, 1 given
2323
ArgumentCountError
24-
At least 2 parameters are required, 1 given
24+
At least 2 arguments are required, 1 given

Zend/zend_execute.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,19 @@ static zend_never_inline ZEND_COLD bool zend_wrong_assign_to_variable_reference(
583583
return 1;
584584
}
585585

586+
ZEND_API void zend_cannot_pass_by_reference(uint32_t arg_num)
587+
{
588+
const zend_execute_data *execute_data = EG(current_execute_data);
589+
zend_string *func_name = get_function_or_method_name(EX(call)->func);
590+
const char *param_name = get_function_arg_name(EX(call)->func, arg_num);
591+
592+
zend_throw_error(NULL, "%s(): Argument #%d%s%s%s cannot be passed by reference",
593+
ZSTR_VAL(func_name), arg_num, param_name ? " ($" : "", param_name ? param_name : "", param_name ? ")" : ""
594+
);
595+
596+
zend_string_release(func_name);
597+
}
598+
586599
static zend_never_inline ZEND_COLD void zend_throw_auto_init_in_prop_error(zend_property_info *prop, const char *type) {
587600
zend_string *type_str = zend_type_to_string(prop->type);
588601
zend_type_error(

Zend/zend_execute.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,7 @@ ZEND_API void ZEND_FASTCALL zend_free_extra_named_params(zend_array *extra_named
308308

309309
/* services */
310310
ZEND_API const char *get_active_class_name(const char **space);
311-
ZEND_API const char *get_class_name(const zend_function *func, const char **space);
312311
ZEND_API const char *get_active_function_name(void);
313-
ZEND_API const char *get_function_name(const zend_function *func);
314312
ZEND_API const char *get_active_function_arg_name(uint32_t arg_num);
315313
ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num);
316314
ZEND_API zend_string *get_active_function_or_method_name();
@@ -320,6 +318,7 @@ ZEND_API zend_string *zend_get_executed_filename_ex(void);
320318
ZEND_API uint32_t zend_get_executed_lineno(void);
321319
ZEND_API zend_class_entry *zend_get_executed_scope(void);
322320
ZEND_API zend_bool zend_is_executing(void);
321+
ZEND_API void zend_cannot_pass_by_reference(uint32_t arg_num);
323322

324323
ZEND_API void zend_set_timeout(zend_long seconds, bool reset_signals);
325324
ZEND_API void zend_unset_timeout(void);

Zend/zend_execute_API.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,17 @@ void shutdown_executor(void) /* {{{ */
433433
/* return class name and "::" or "". */
434434
ZEND_API const char *get_active_class_name(const char **space) /* {{{ */
435435
{
436+
zend_function *func;
437+
436438
if (!zend_is_executing()) {
437439
if (space) {
438440
*space = "";
439441
}
440442
return "";
441443
}
442444

443-
return get_class_name(EG(current_execute_data)->func, space);
444-
}
445-
/* }}} */
445+
func = EG(current_execute_data)->func;
446446

447-
/* return class name and "::" or "". */
448-
ZEND_API const char *get_class_name(const zend_function *func, const char **space) /* {{{ */
449-
{
450447
switch (func->type) {
451448
case ZEND_USER_FUNCTION:
452449
case ZEND_INTERNAL_FUNCTION:
@@ -469,16 +466,14 @@ ZEND_API const char *get_class_name(const zend_function *func, const char **spac
469466

470467
ZEND_API const char *get_active_function_name(void) /* {{{ */
471468
{
469+
zend_function *func;
470+
472471
if (!zend_is_executing()) {
473472
return NULL;
474473
}
475474

476-
return get_function_name(EG(current_execute_data)->func);
477-
}
478-
/* }}} */
475+
func = EG(current_execute_data)->func;
479476

480-
ZEND_API const char *get_function_name(const zend_function *func) /* {{{ */
481-
{
482477
switch (func->type) {
483478
case ZEND_USER_FUNCTION: {
484479
zend_string *function_name = func->common.function_name;
@@ -501,9 +496,7 @@ ZEND_API const char *get_function_name(const zend_function *func) /* {{{ */
501496

502497
ZEND_API zend_string *get_active_function_or_method_name(void) /* {{{ */
503498
{
504-
if (!zend_is_executing()) {
505-
return zend_string_init("", 0, 0);
506-
}
499+
ZEND_ASSERT(zend_is_executing());
507500

508501
return get_function_or_method_name(EG(current_execute_data)->func);
509502
}

Zend/zend_vm_def.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4594,16 +4594,10 @@ ZEND_VM_HOT_HANDLER(65, ZEND_SEND_VAL, CONST|TMPVAR, CONST|UNUSED|NUM)
45944594
ZEND_VM_COLD_HELPER(zend_cannot_pass_by_ref_helper, ANY, ANY, uint32_t _arg_num, zval *_arg)
45954595
{
45964596
USE_OPLINE
4597-
zend_string *func_name = get_function_or_method_name(EX(call)->func);
4598-
const char *param_name = get_function_arg_name(EX(call)->func, _arg_num);
45994597

46004598
SAVE_OPLINE();
46014599

4602-
zend_throw_error(NULL, "%s(): Argument #%d%s%s%s cannot be passed by reference",
4603-
ZSTR_VAL(func_name), _arg_num, param_name ? " ($" : "",
4604-
param_name ? param_name : "", param_name ? ")" : ""
4605-
);
4606-
zend_string_release(func_name);
4600+
zend_cannot_pass_by_reference(_arg_num);
46074601
FREE_OP1();
46084602
ZVAL_UNDEF(_arg);
46094603
HANDLE_EXCEPTION();

Zend/zend_vm_execute.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,16 +2281,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_CREATE_SPEC_HANDLER(
22812281
static zend_never_inline ZEND_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_cannot_pass_by_ref_helper_SPEC(uint32_t _arg_num, zval *_arg ZEND_OPCODE_HANDLER_ARGS_DC)
22822282
{
22832283
USE_OPLINE
2284-
zend_string *func_name = get_function_or_method_name(EX(call)->func);
2285-
const char *param_name = get_function_arg_name(EX(call)->func, _arg_num);
22862284

22872285
SAVE_OPLINE();
22882286

2289-
zend_throw_error(NULL, "%s(): Argument #%d%s%s%s cannot be passed by reference",
2290-
ZSTR_VAL(func_name), _arg_num, param_name ? " ($" : "",
2291-
param_name ? param_name : "", param_name ? ")" : ""
2292-
);
2293-
zend_string_release(func_name);
2287+
zend_cannot_pass_by_reference(_arg_num);
22942288
FREE_OP(opline->op1_type, opline->op1.var);
22952289
ZVAL_UNDEF(_arg);
22962290
HANDLE_EXCEPTION();

ext/opcache/jit/zend_jit_disasm_x86.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ static int zend_jit_disasm_init(void)
450450
REGISTER_HELPER(zend_jit_post_dec_typed_ref);
451451
REGISTER_HELPER(zend_jit_assign_op_to_typed_ref);
452452
REGISTER_HELPER(zend_jit_only_vars_by_reference);
453-
REGISTER_HELPER(zend_jit_cannot_pass_by_reference);
454453
REGISTER_HELPER(zend_jit_invalid_array_access);
455454
REGISTER_HELPER(zend_jit_invalid_property_read);
456455
REGISTER_HELPER(zend_jit_invalid_property_write);

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,19 +1769,6 @@ static void ZEND_FASTCALL zend_jit_only_vars_by_reference(zval *arg)
17691769
zend_error(E_NOTICE, "Only variables should be passed by reference");
17701770
}
17711771

1772-
static void ZEND_FASTCALL zend_jit_cannot_pass_by_reference(uint32_t arg_num)
1773-
{
1774-
const zend_execute_data *execute_data = EG(current_execute_data);
1775-
zend_string *func_name = get_function_or_method_name(EX(call)->func);
1776-
const char *param_name = get_function_arg_name(EX(call)->func, arg_num);
1777-
1778-
zend_throw_error(NULL, "%s(): Argument #%d%s%s%s cannot be passed by reference",
1779-
ZSTR_VAL(func_name), arg_num, param_name ? " ($" : "", param_name ? param_name : "", param_name ? ")" : ""
1780-
);
1781-
1782-
zend_string_release(func_name);
1783-
}
1784-
17851772
static void ZEND_FASTCALL zend_jit_invalid_array_access(zval *container)
17861773
{
17871774
zend_error(E_WARNING, "Trying to access array offset on value of type %s", zend_zval_type_name(container));

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,12 +1912,8 @@ static int zend_jit_throw_cannot_pass_by_ref_stub(dasm_State **Dst)
19121912
| mov EX->call, RX
19131913
|1:
19141914
| mov RX, r0
1915-
|.if X64
1916-
| mov CARG1d, dword OP:r0->op2.num
1917-
|.else
1918-
| mov r1, dword OP:r0->op2.num
1919-
|.endif
1920-
| EXT_CALL zend_jit_cannot_pass_by_reference, r0
1915+
| mov FCARG1d, dword OP:r0->op2.num
1916+
| EXT_CALL zend_cannot_pass_by_reference, r0
19211917
| cmp byte OP:RX->op1_type, IS_TMP_VAR
19221918
| jne >9
19231919
|.if X64

ext/standard/array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5024,7 +5024,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty
50245024
argc = ZEND_NUM_ARGS();
50255025
if (data_compare_type == DIFF_COMP_DATA_USER) {
50265026
if (argc < 3) {
5027-
zend_argument_count_error("At least 3 parameters are required, %d given", ZEND_NUM_ARGS());
5027+
zend_argument_count_error("At least 3 arguments are required, %d given", ZEND_NUM_ARGS());
50285028
RETURN_THROWS();
50295029
}
50305030
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+f", &args, &argc, &BG(user_compare_fci), &BG(user_compare_fci_cache)) == FAILURE) {
@@ -5033,7 +5033,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty
50335033
diff_data_compare_func = zval_user_compare;
50345034
} else {
50355035
if (argc < 2) {
5036-
zend_argument_count_error("At least 2 parameters are required, %d given", ZEND_NUM_ARGS());
5036+
zend_argument_count_error("At least 2 arguments are required, %d given", ZEND_NUM_ARGS());
50375037
RETURN_THROWS();
50385038
}
50395039
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
@@ -5378,7 +5378,7 @@ PHP_FUNCTION(array_diff)
53785378
zval dummy;
53795379

53805380
if (ZEND_NUM_ARGS() < 2) {
5381-
zend_argument_count_error("At least 2 parameters are required, %d given", ZEND_NUM_ARGS());
5381+
zend_argument_count_error("At least 2 arguments are required, %d given", ZEND_NUM_ARGS());
53825382
RETURN_THROWS();
53835383
}
53845384

ext/standard/formatted_print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n
719719
if (nb_additional_parameters == -1) {
720720
zend_value_error("The arguments array must contain %d items, %d given", max_missing_argnum + 1, argc);
721721
} else {
722-
zend_argument_count_error("%d parameters are required, %d given", max_missing_argnum + nb_additional_parameters + 1, argc + nb_additional_parameters);
722+
zend_argument_count_error("%d arguments are required, %d given", max_missing_argnum + nb_additional_parameters + 1, argc + nb_additional_parameters);
723723
}
724724
goto fail;
725725
}

ext/standard/tests/array/array_diff_assoc_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ echo "Done";
3131
*** Testing array_diff_assoc() : error conditions ***
3232

3333
-- Testing array_diff_assoc() function with zero arguments --
34-
At least 2 parameters are required, 0 given
34+
At least 2 arguments are required, 0 given
3535

3636
-- Testing array_diff_assoc() function with less than expected no. of arguments --
37-
At least 2 parameters are required, 1 given
37+
At least 2 arguments are required, 1 given
3838
Done

ext/standard/tests/array/array_diff_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ echo "Done";
3131
*** Testing array_diff() : error conditions ***
3232

3333
-- Testing array_diff() function with zero arguments --
34-
At least 2 parameters are required, 0 given
34+
At least 2 arguments are required, 0 given
3535

3636
-- Testing array_diff() function with less than expected no. of arguments --
37-
At least 2 parameters are required, 1 given
37+
At least 2 arguments are required, 1 given
3838
Done

ext/standard/tests/array/array_diff_key_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ try {
2727
*** Testing array_diff_key() : error conditions ***
2828

2929
-- Testing array_diff_key() function with less than expected no. of arguments --
30-
At least 2 parameters are required, 1 given
30+
At least 2 arguments are required, 1 given
3131

3232
-- Testing array_diff_key() function with no arguments --
33-
At least 2 parameters are required, 0 given
33+
At least 2 arguments are required, 0 given

ext/standard/tests/strings/printf.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ printf("%d", $tempstring);
238238
?>
239239
--EXPECTF--
240240
*** Output for zero argument ***
241-
printf() expects at least %d parameter, %d given
241+
printf() expects at least %d argument, %d given
242242

243243
*** Output for insufficient number of arguments ***
244-
Error found: arguments are required, given
244+
Error found: %d arguments are required, %d given
245245
*** Output for scalar argument ***
246246
3
247247
*** Output for NULL as argument ***

ext/standard/tests/strings/printf_64bit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ printf("%d", $tempstring);
241241
printf() expects at least 1 argument, 0 given
242242

243243
*** Output for insufficient number of arguments ***
244-
Error found: 5 parameters are required, 3 given
244+
Error found: 5 arguments are required, 3 given
245245
*** Output for scalar argument ***
246246
3
247247
*** Output for NULL as argument ***

ext/standard/tests/strings/printf_error.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ printf() expects at least 1 argument, 0 given
6565
-- Testing printf() function with less than expected no. of arguments --
6666

6767
-- Call printf with one argument less than expected --
68-
2 parameters are required, 1 given
69-
3 parameters are required, 2 given
70-
4 parameters are required, 3 given
68+
2 arguments are required, 1 given
69+
3 arguments are required, 2 given
70+
4 arguments are required, 3 given
7171

7272
-- Call printf with two argument less than expected --
73-
3 parameters are required, 1 given
74-
4 parameters are required, 2 given
73+
3 arguments are required, 1 given
74+
4 arguments are required, 2 given
7575

7676
-- Call printf with three argument less than expected --
77-
4 parameters are required, 1 given
77+
4 arguments are required, 1 given

ext/standard/tests/strings/sprintf_error.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ echo "Done";
7676
sprintf() expects at least 1 argument, 0 given
7777

7878
-- Testing sprintf() function with less than expected no. of arguments --
79-
2 parameters are required, 1 given
80-
3 parameters are required, 2 given
81-
4 parameters are required, 3 given
82-
3 parameters are required, 1 given
83-
4 parameters are required, 2 given
84-
4 parameters are required, 1 given
85-
101 parameters are required, 1 given
79+
2 arguments are required, 1 given
80+
3 arguments are required, 2 given
81+
4 arguments are required, 3 given
82+
3 arguments are required, 1 given
83+
4 arguments are required, 2 given
84+
4 arguments are required, 1 given
85+
101 arguments are required, 1 given
8686
Missing format specifier at end of string
8787
Done

0 commit comments

Comments
 (0)