Skip to content

Commit

Permalink
- Strip out the typehint *checks* only. They are still parsed, and th…
Browse files Browse the repository at this point in the history
…ey are

  still accessible through the reflection API.
  • Loading branch information
Derick Rethans committed Oct 19, 2010
1 parent defd00a commit 0e24a7c
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 291 deletions.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
FR #51815. (Pierrick)
- Added iterator support in MySQLi. mysqli_result implements Traversable.
(Andrey, Johannes)
- Added scalar typehinting. (Ilia, Derick)
- Added scalar typehints to the parser and the reflection API. (Ilia, Derick)
- Added support for JSON_NUMERIC_CHECK option in json_encode() that converts
numeric strings to integers. (Ilia)
- Added support for object references in recursive serialize() calls. FR #36424.
Expand Down
38 changes: 0 additions & 38 deletions Zend/tests/hint/param_type_hint_001.phpt

This file was deleted.

16 changes: 0 additions & 16 deletions Zend/tests/hint/param_type_hint_003.phpt

This file was deleted.

16 changes: 0 additions & 16 deletions Zend/tests/hint/param_type_hint_004.phpt

This file was deleted.

23 changes: 0 additions & 23 deletions Zend/tests/hint/param_type_hint_005.phpt

This file was deleted.

15 changes: 0 additions & 15 deletions Zend/tests/hint/param_type_hint_011.phpt

This file was deleted.

18 changes: 0 additions & 18 deletions Zend/tests/hint/param_type_hint_012.phpt

This file was deleted.

16 changes: 0 additions & 16 deletions Zend/tests/hint/param_type_hint_013.phpt

This file was deleted.

16 changes: 0 additions & 16 deletions Zend/tests/hint/param_type_hint_014.phpt

This file was deleted.

19 changes: 0 additions & 19 deletions Zend/tests/hint/param_type_hint_015.phpt

This file was deleted.

37 changes: 0 additions & 37 deletions Zend/tests/hint/param_type_hint_019.phpt

This file was deleted.

46 changes: 0 additions & 46 deletions Zend/tests/hint/param_type_hint_021.phpt

This file was deleted.

41 changes: 11 additions & 30 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ static inline void make_real_object(zval **object_ptr TSRMLS_DC)
}
}

static inline char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, ulong fetch_type, const char **class_name, zend_class_entry **pce TSRMLS_DC)
ZEND_API char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, ulong fetch_type, const char **class_name, zend_class_entry **pce TSRMLS_DC)
{
*pce = zend_fetch_class(cur_arg_info->class_name, cur_arg_info->class_name_len, (fetch_type | ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD) TSRMLS_CC);

Expand All @@ -589,7 +589,7 @@ static inline char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_inf
}
}

static inline int zend_verify_arg_error(const zend_function *zf, zend_uint arg_num, const char *need_msg, const char *need_kind, const char *given_msg, char *given_kind TSRMLS_DC)
ZEND_API int zend_verify_arg_error(int error_type, const zend_function *zf, zend_uint arg_num, const char *need_msg, const char *need_kind, const char *given_msg, char *given_kind TSRMLS_DC)
{
zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data;
char *fname = zf->common.function_name;
Expand All @@ -605,9 +605,9 @@ static inline int zend_verify_arg_error(const zend_function *zf, zend_uint arg_n
}

if (ptr && ptr->op_array) {
zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s%s, %s%s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind, ptr->op_array->filename, ptr->opline->lineno);
zend_error(error_type, "Argument %d passed to %s%s%s() must %s%s, %s%s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind, ptr->op_array->filename, ptr->opline->lineno);
} else {
zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s%s, %s%s given", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind);
zend_error(error_type, "Argument %d passed to %s%s%s() must %s%s, %s%s given", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind);
}
return 0;
}
Expand All @@ -630,44 +630,25 @@ static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zva

if (!arg) {
need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
return zend_verify_arg_error(zf, arg_num, need_msg, class_name, "none", "" TSRMLS_CC);
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, "none", "" TSRMLS_CC);
}
if (Z_TYPE_P(arg) == IS_OBJECT) {
need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
if (!ce || !instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) {
return zend_verify_arg_error(zf, arg_num, need_msg, class_name, "instance of ", Z_OBJCE_P(arg)->name TSRMLS_CC);
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, "instance of ", Z_OBJCE_P(arg)->name TSRMLS_CC);
}
} else if (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null) {
need_msg = zend_verify_arg_class_kind(cur_arg_info, fetch_type, &class_name, &ce TSRMLS_CC);
return zend_verify_arg_error(zf, arg_num, need_msg, class_name, zend_zval_type_name(arg), "" TSRMLS_CC);
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, need_msg, class_name, zend_zval_type_name(arg), "" TSRMLS_CC);
}
} else if (cur_arg_info->type_hint) {
} else if (cur_arg_info->type_hint && cur_arg_info->type_hint == IS_ARRAY) {
if (!arg) {
return zend_verify_arg_error(zf, arg_num, "be of the type ", zend_get_type_by_const(cur_arg_info->type_hint), "none", "" TSRMLS_CC);
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", "none", "" TSRMLS_CC);
}

/* existing type already matches the hint or forced type */
if (Z_TYPE_P(arg) == cur_arg_info->type_hint) {
return 1;
if (Z_TYPE_P(arg) != IS_ARRAY && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) {
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be of the type array", "", zend_zval_type_name(arg), "" TSRMLS_CC);
}

/* NULL type given, check if parameter is optional */
if (Z_TYPE_P(arg) == IS_NULL && cur_arg_info->allow_null) {
return 1;
}

if (cur_arg_info->type_hint == IS_SCALAR && Z_TYPE_P(arg) != IS_NULL && Z_TYPE_P(arg) != IS_ARRAY && Z_TYPE_P(arg) != IS_OBJECT && Z_TYPE_P(arg) != IS_RESOURCE) {
return 1;
}

if (cur_arg_info->type_hint == IS_NUMERIC && (
(Z_TYPE_P(arg) == IS_LONG || Z_TYPE_P(arg) == IS_DOUBLE)
|| (Z_TYPE_P(arg) == IS_STRING && is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), NULL, NULL, 0))
)) {
return 1;
}

return zend_verify_arg_error(zf, arg_num, "be of the type ", zend_get_type_by_const(cur_arg_info->type_hint), "", zend_zval_type_name(arg) TSRMLS_CC);
}
return 1;
}
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ ZEND_API int zend_eval_stringl(char *str, int str_len, zval *retval_ptr, char *s
ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC);
ZEND_API int zend_eval_stringl_ex(char *str, int str_len, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC);

ZEND_API char * zend_verify_arg_class_kind(const zend_arg_info *cur_arg_info, ulong fetch_type, const char **class_name, zend_class_entry **pce TSRMLS_DC);
ZEND_API int zend_verify_arg_error(int error_type, const zend_function *zf, zend_uint arg_num, const char *need_msg, const char *need_kind, const char *given_msg, char *given_kind TSRMLS_DC);

static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC)
{
if (!Z_DELREF_P(zval_ptr)) {
Expand Down

0 comments on commit 0e24a7c

Please sign in to comment.