Skip to content

Commit 61b3d5c

Browse files
author
Moriyoshi Koizumi
committed
Fixed incorrect error messages of array_walk() in case the callback is
specified in an array form
1 parent 397b35f commit 61b3d5c

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

ext/standard/array.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,37 @@ static int php_array_walk(HashTable *target_hash, zval **userdata TSRMLS_DC)
980980

981981
zval_ptr_dtor(&retval_ptr);
982982
} else {
983-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s() - function does not exist",
983+
if (Z_TYPE_PP(BG(array_walk_func_name)) == IS_STRING) {
984+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s() - function does not exist",
984985
(*BG(array_walk_func_name))->value.str.val);
986+
} else if (Z_TYPE_PP(BG(array_walk_func_name)) == IS_ARRAY) {
987+
char *obj_name = NULL;
988+
zval **obj;
989+
zval **mt_name;
990+
991+
if (zend_hash_index_find(Z_ARRVAL_PP(BG(array_walk_func_name)),
992+
0, (void **)&obj) == SUCCESS
993+
&& zend_hash_index_find(Z_ARRVAL_PP(BG(array_walk_func_name)),
994+
1, (void **)&mt_name) == SUCCESS
995+
&& Z_TYPE_PP(mt_name) == IS_STRING) {
996+
switch (Z_TYPE_PP(obj)) {
997+
case IS_OBJECT:
998+
obj_name = Z_OBJ_PP(obj)->ce->name;
999+
break;
1000+
1001+
case IS_STRING:
1002+
obj_name = Z_STRVAL_PP(obj);
1003+
break;
1004+
}
1005+
}
1006+
1007+
if (obj_name != NULL) {
1008+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s::%s() - function does not exist",
1009+
obj_name, Z_STRVAL_PP(mt_name));
1010+
} else {
1011+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid function name");
1012+
}
1013+
}
9851014
}
9861015

9871016
zend_hash_move_forward_ex(target_hash, &pos);

0 commit comments

Comments
 (0)