From 32d69c853a8a4710c623307e7bb2e3feb5a2f82e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 5 Aug 2005 09:35:09 +0000 Subject: [PATCH] Fixed bug #33996 (No information given for fatal error on passing invalid value to typed argument) --- NEWS | 2 ++ Zend/tests/array_type_hint_001.phpt | 2 +- Zend/tests/bug33996.phpt | 29 +++++++++++++++++++ Zend/zend_execute.c | 43 ++++++++++++++++++++++++----- tests/classes/type_hinting_001.phpt | 2 +- tests/lang/type_hints_001.phpt | 2 +- 6 files changed, 70 insertions(+), 10 deletions(-) create mode 100755 Zend/tests/bug33996.phpt diff --git a/NEWS b/NEWS index 412feb99e3..419b57b030 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2005, PHP 5.1 - Fixed bug #33999 (object remains object when cast to int). (Dmitry) +- Fixed bug #33996 (No information given for fatal error on passing invalid + value to typed argument). (Dmitry) - Fixed bug #33989 (extract($GLOBALS,EXTR_REFS) crashes PHP). (Dmitry) - Fixed bug #33967 (misuse of Exception constructor doesn't display errorfile). (Jani) diff --git a/Zend/tests/array_type_hint_001.phpt b/Zend/tests/array_type_hint_001.phpt index c21c503d43..b110622aeb 100755 --- a/Zend/tests/array_type_hint_001.phpt +++ b/Zend/tests/array_type_hint_001.phpt @@ -12,4 +12,4 @@ foo(123); --EXPECTF-- 3 -Fatal error: Argument 1 must be an array in %sarray_type_hint_001.php on line 2 \ No newline at end of file +Fatal error: Argument 1 must be an array, called in %sarray_type_hint_001.php on line 7 and defined in %sarray_type_hint_001.php on line 2 diff --git a/Zend/tests/bug33996.phpt b/Zend/tests/bug33996.phpt new file mode 100755 index 0000000000..9b52f02a8f --- /dev/null +++ b/Zend/tests/bug33996.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #33996 (No information given for fatal error on passing invalid value to typed argument) +--INI-- +error_reporting=4095 +--FILE-- + +--EXPECTF-- +Warning: Missing argument 1 for NormalTest(), called in %sbug33996.php on line 17 and defined in %sbug33996.php on line 12 +Hi! +Fatal error: Argument 1 must be an object of class Foo, called in %sbug33996.php on line 18 and defined in %sbug33996.php on line 7 diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 178d1bb643..888b60e9d2 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -447,6 +447,7 @@ static inline void make_real_object(zval **object_ptr TSRMLS_DC) static inline void zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zval *arg TSRMLS_DC) { zend_arg_info *cur_arg_info; + zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data; if (!zf->common.arg_info || arg_num>zf->common.num_args) { @@ -457,12 +458,20 @@ static inline void zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zv if (cur_arg_info->class_name) { if (!arg) { - zend_error_noreturn(E_ERROR, "Argument %d must be an object of class %s", arg_num, cur_arg_info->class_name); + if(ptr && ptr->op_array) { + zend_error_noreturn(E_ERROR, "Argument %d must be an object of class %s, called in %s on line %d and defined", arg_num, cur_arg_info->class_name, ptr->op_array->filename, ptr->opline->lineno); + } else { + zend_error_noreturn(E_ERROR, "Argument %d must be an object of class %s", arg_num, cur_arg_info->class_name); + } } switch (Z_TYPE_P(arg)) { case IS_NULL: if (!cur_arg_info->allow_null) { - zend_error_noreturn(E_ERROR, "Argument %d must not be null", arg_num); + if(ptr && ptr->op_array) { + zend_error_noreturn(E_ERROR, "Argument %d must not be null, called in %s on line %d and defined", arg_num, ptr->op_array->filename, ptr->opline->lineno); + } else { + zend_error_noreturn(E_ERROR, "Argument %d must not be null", arg_num); + } } break; case IS_OBJECT: { @@ -475,28 +484,48 @@ static inline void zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zv } else { error_msg = "be an instance of"; } - zend_error_noreturn(E_ERROR, "Argument %d must %s %s", arg_num, error_msg, ce->name); + if(ptr && ptr->op_array) { + zend_error_noreturn(E_ERROR, "Argument %d must %s %s, called in %s on line %d and defined", arg_num, error_msg, ce->name, ptr->op_array->filename, ptr->opline->lineno); + } else { + zend_error_noreturn(E_ERROR, "Argument %d must %s %s", arg_num, error_msg, ce->name); + } } } break; default: - zend_error_noreturn(E_ERROR, "Argument %d must be an object of class %s", arg_num, cur_arg_info->class_name); + if(ptr && ptr->op_array) { + zend_error_noreturn(E_ERROR, "Argument %d must be an object of class %s, called in %s on line %d and defined", arg_num, cur_arg_info->class_name, ptr->op_array->filename, ptr->opline->lineno); + } else { + zend_error_noreturn(E_ERROR, "Argument %d must be an object of class %s", arg_num, cur_arg_info->class_name); + } break; } } else if (cur_arg_info->array_type_hint) { if (!arg) { - zend_error_noreturn(E_ERROR, "Argument %d must be an array", arg_num); + if(ptr && ptr->op_array) { + zend_error_noreturn(E_ERROR, "Argument %d must be an array, called in %s on line %d and defined", arg_num, ptr->op_array->filename, ptr->opline->lineno); + } else { + zend_error_noreturn(E_ERROR, "Argument %d must be an array", arg_num); + } } switch (Z_TYPE_P(arg)) { case IS_NULL: if (!cur_arg_info->allow_null) { - zend_error_noreturn(E_ERROR, "Argument %d must not be null", arg_num); + if(ptr && ptr->op_array) { + zend_error_noreturn(E_ERROR, "Argument %d must not be null, called in %s on line %d and defined", arg_num, ptr->op_array->filename, ptr->opline->lineno); + } else { + zend_error_noreturn(E_ERROR, "Argument %d must not be null", arg_num); + } } break; case IS_ARRAY: break; default: - zend_error_noreturn(E_ERROR, "Argument %d must be an array", arg_num); + if(ptr && ptr->op_array) { + zend_error_noreturn(E_ERROR, "Argument %d must be an array, called in %s on line %d and defined", arg_num, ptr->op_array->filename, ptr->opline->lineno); + } else { + zend_error_noreturn(E_ERROR, "Argument %d must be an array", arg_num); + } break; } } diff --git a/tests/classes/type_hinting_001.phpt b/tests/classes/type_hinting_001.phpt index d4042a496d..c46e420ab6 100644 --- a/tests/classes/type_hinting_001.phpt +++ b/tests/classes/type_hinting_001.phpt @@ -35,4 +35,4 @@ $a->b($b); ?> --EXPECTF-- -Fatal error: Argument 1 must implement interface Foo in %s on line %d +Fatal error: Argument 1 must implement interface Foo, called in %s on line 27 and defined in %s on line 12 diff --git a/tests/lang/type_hints_001.phpt b/tests/lang/type_hints_001.phpt index 99b7fac0eb..2aea3e703e 100644 --- a/tests/lang/type_hints_001.phpt +++ b/tests/lang/type_hints_001.phpt @@ -23,4 +23,4 @@ type_hint_foo($bar); ?> --EXPECTF-- -Fatal error: Argument 1 must be an instance of Foo in %s on line %d +Fatal error: Argument 1 must be an instance of Foo, called in %s on line 16 and defined in %s on line 9 -- 2.50.1