Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages mentioning parameters instead of arguments #5999

Closed
wants to merge 6 commits into from

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Aug 16, 2020

  • Cannot pass parameter 1 by reference -> test(): Argument #1 ($param) cannot be passed by reference
  • str_pad() expects at least 2 parameters, 1 given -> str_pad() expects at least 2 arguments, 1 given
  • Warning: count(): Parameter must be an array or an object that implements Countable -> Warning: count(): Argument #1 ($var) must be of type Countable|array, Generator given

@kocsismate kocsismate force-pushed the pass-by-arg branch 2 times, most recently from 9425533 to c0422ce Compare August 16, 2020 23:35
@kocsismate kocsismate changed the title Improve error message for 'Cannot pass parameter by reference' Improve error messages mentioning parameters instead of arguments Aug 16, 2020
@kocsismate kocsismate force-pushed the pass-by-arg branch 5 times, most recently from 0257580 to 86fecd9 Compare August 17, 2020 08:26
@kocsismate kocsismate force-pushed the pass-by-arg branch 5 times, most recently from f114414 to 25bbdcc Compare August 31, 2020 09:35
@kocsismate kocsismate force-pushed the pass-by-arg branch 3 times, most recently from 32038d6 to 84557e1 Compare September 4, 2020 16:34
return zend_create_member_string(func->common.scope->name, func->common.function_name);
}

return func->common.function_name ? zend_string_copy(func->common.function_name) : zend_string_init("main", sizeof("main") - 1, 0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or alternatively, should we could add an assert that function_name is not null?

/* }}} */

/* return class name and "::" or "". */
ZEND_API const char *get_class_name(const zend_function *func, const char **space) /* {{{ */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem needed for anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that they will come handy in the future, but probably we shouldn't prematurely optimize for the future in this case :) so I've just removed the unneeded functions.

}
/* }}} */

ZEND_API const char *get_function_name(const zend_function *func) /* {{{ */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem needed for anything?

{
if (!zend_is_executing()) {
return zend_string_init("", 0, 0);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can ZEND_ASSERT this, I think.

);

zend_string_release(func_name);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have this in a function in zend_execute.c that can be used both by zend_vm_def and jit?

| LOAD_ADDR CARG2, "Cannot pass parameter %d by reference"
| mov CARG3d, dword OP:r0->op2.num
| EXT_CALL zend_throw_error, r0
| mov CARG1d, dword OP:r0->op2.num
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| mov CARG1d, dword OP:r0->op2.num
| mov FCARG1d, dword OP:r0->op2.num

and drop the if/else.

@kocsismate kocsismate force-pushed the pass-by-arg branch 4 times, most recently from 4ae6447 to 910a199 Compare September 8, 2020 18:45
@@ -583,6 +583,19 @@ static zend_never_inline ZEND_COLD bool zend_wrong_assign_to_variable_reference(
return 1;
}

ZEND_API void zend_cannot_pass_by_reference(uint32_t arg_num)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ZEND_API void zend_cannot_pass_by_reference(uint32_t arg_num)
ZEND_API ZEND_COLD void zend_cannot_pass_by_reference(uint32_t arg_num)

@php-pulls php-pulls closed this in 9975986 Sep 9, 2020
@kocsismate kocsismate deleted the pass-by-arg branch September 9, 2020 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants