Skip to content

Commit 6db97f5

Browse files
committed
Remove each()
This has been deprecated in PHP 7.2 as part of https://wiki.php.net/rfc/deprecations_php_7_2.
1 parent 9bc2cac commit 6db97f5

20 files changed

+1
-1346
lines changed

UPGRADING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ PHP 8.0 UPGRADE NOTES
2424
. Removed track_errors ini directive. This means that $php_errormsg is no
2525
longer available. The error_get_last() function may be used instead.
2626
. Removed create_function(). Anonymous functions may be used instead.
27+
. Removed each(). foreach or ArrayIterator should be used instead.
2728

2829
- GD:
2930
. The deprecated function image2wbmp() has been removed.

Zend/tests/007.phpt

Lines changed: 0 additions & 65 deletions
This file was deleted.

Zend/tests/each_001.phpt

Lines changed: 0 additions & 12 deletions
This file was deleted.

Zend/tests/each_002.phpt

Lines changed: 0 additions & 33 deletions
This file was deleted.

Zend/tests/each_003.phpt

Lines changed: 0 additions & 27 deletions
This file was deleted.

Zend/zend_builtin_functions.c

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static ZEND_FUNCTION(strcmp);
3737
static ZEND_FUNCTION(strncmp);
3838
static ZEND_FUNCTION(strcasecmp);
3939
static ZEND_FUNCTION(strncasecmp);
40-
static ZEND_FUNCTION(each);
4140
static ZEND_FUNCTION(error_reporting);
4241
static ZEND_FUNCTION(define);
4342
static ZEND_FUNCTION(defined);
@@ -108,10 +107,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_strncmp, 0, 0, 3)
108107
ZEND_ARG_INFO(0, len)
109108
ZEND_END_ARG_INFO()
110109

111-
ZEND_BEGIN_ARG_INFO_EX(arginfo_each, 0, 0, 1)
112-
ZEND_ARG_INFO(1, arr)
113-
ZEND_END_ARG_INFO()
114-
115110
ZEND_BEGIN_ARG_INFO_EX(arginfo_error_reporting, 0, 0, 0)
116111
ZEND_ARG_INFO(0, new_error_level)
117112
ZEND_END_ARG_INFO()
@@ -238,7 +233,6 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */
238233
ZEND_FE(strncmp, arginfo_strncmp)
239234
ZEND_FE(strcasecmp, arginfo_strcmp)
240235
ZEND_FE(strncasecmp, arginfo_strncmp)
241-
ZEND_FE(each, arginfo_each)
242236
ZEND_FE(error_reporting, arginfo_error_reporting)
243237
ZEND_FE(define, arginfo_define)
244238
ZEND_FE(defined, arginfo_defined)
@@ -653,66 +647,6 @@ ZEND_FUNCTION(strncasecmp)
653647
}
654648
/* }}} */
655649

656-
/* {{{ proto mixed each(array &arr)
657-
Return the currently pointed key..value pair in the passed array, and advance the pointer to the next element, or false if there is no element at this place */
658-
ZEND_FUNCTION(each)
659-
{
660-
zval *array, *entry, tmp;
661-
zend_ulong num_key;
662-
HashTable *target_hash;
663-
zend_string *key;
664-
665-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &array) == FAILURE) {
666-
return;
667-
}
668-
669-
if (!EG(each_deprecation_thrown)) {
670-
zend_error(E_DEPRECATED, "The each() function is deprecated. This message will be suppressed on further calls");
671-
EG(each_deprecation_thrown) = 1;
672-
}
673-
674-
target_hash = HASH_OF(array);
675-
if (!target_hash) {
676-
zend_error(E_WARNING,"Variable passed to each() is not an array or object");
677-
return;
678-
}
679-
while (1) {
680-
entry = zend_hash_get_current_data(target_hash);
681-
if (!entry) {
682-
RETURN_FALSE;
683-
} else if (Z_TYPE_P(entry) == IS_INDIRECT) {
684-
entry = Z_INDIRECT_P(entry);
685-
if (Z_TYPE_P(entry) == IS_UNDEF) {
686-
zend_hash_move_forward(target_hash);
687-
continue;
688-
}
689-
}
690-
break;
691-
}
692-
array_init_size(return_value, 4);
693-
zend_hash_real_init_mixed(Z_ARRVAL_P(return_value));
694-
695-
/* add value elements */
696-
ZVAL_DEREF(entry);
697-
if (Z_REFCOUNTED_P(entry)) {
698-
GC_ADDREF_EX(Z_COUNTED_P(entry), 2);
699-
}
700-
zend_hash_index_add_new(Z_ARRVAL_P(return_value), 1, entry);
701-
zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_VALUE), entry);
702-
703-
/* add the key elements */
704-
if (zend_hash_get_current_key(target_hash, &key, &num_key) == HASH_KEY_IS_STRING) {
705-
ZVAL_STR_COPY(&tmp, key);
706-
Z_TRY_ADDREF(tmp);
707-
} else {
708-
ZVAL_LONG(&tmp, num_key);
709-
}
710-
zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp);
711-
zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_KEY), &tmp);
712-
zend_hash_move_forward(target_hash);
713-
}
714-
/* }}} */
715-
716650
/* {{{ proto int error_reporting([int new_error_level])
717651
Return the current error_reporting level, and if an argument was passed - change to the new level */
718652
ZEND_FUNCTION(error_reporting)

Zend/zend_execute_API.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ void init_executor(void) /* {{{ */
177177
EG(ht_iterators) = EG(ht_iterators_slots);
178178
memset(EG(ht_iterators), 0, sizeof(EG(ht_iterators_slots)));
179179

180-
EG(each_deprecation_thrown) = 0;
181-
182180
EG(persistent_constants_count) = EG(zend_constants)->nNumUsed;
183181
EG(persistent_functions_count) = EG(function_table)->nNumUsed;
184182
EG(persistent_classes_count) = EG(class_table)->nNumUsed;

Zend/zend_globals.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ struct _zend_executor_globals {
225225
zend_function trampoline;
226226
zend_op call_trampoline_op;
227227

228-
zend_bool each_deprecation_thrown;
229-
230228
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
231229
};
232230

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ static const func_info_t func_infos[] = {
228228
FC("strncmp", zend_lb_ssn_info),
229229
FC("strcasecmp", zend_l_ss_info),
230230
FC("strncasecmp", zend_lb_ssn_info),
231-
F1("each", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_OF_REF | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_KEY_ANY),
232231
F0("error_reporting", MAY_BE_NULL | MAY_BE_LONG),
233232
F0("define", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_NULL), // TODO: inline
234233
FC("defined", zend_b_s_info), // TODO: inline

ext/standard/tests/array/each.phpt

-9.45 KB
Binary file not shown.

ext/standard/tests/array/each_basic.phpt

Lines changed: 0 additions & 76 deletions
This file was deleted.

ext/standard/tests/array/each_error.phpt

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)