Skip to content

Commit 06a0340

Browse files
committed
Deprecate each()
1 parent 6ba7206 commit 06a0340

29 files changed

+79
-43
lines changed

Zend/tests/007.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ echo "Done\n";
2525
Warning: each() expects exactly 1 parameter, 0 given in %s on line %d
2626
NULL
2727

28+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
29+
2830
Warning: Variable passed to each() is not an array or object in %s on line %d
2931
NULL
3032

Zend/tests/each_001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ each($foo);
77

88
?>
99
--EXPECTF--
10+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
11+
1012
Warning: Variable passed to each() is not an array or object in %s on line %d

Zend/tests/each_002.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var_dump(each($a));
1616

1717
?>
1818
--EXPECTF--
19+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
1920
bool(false)
2021
bool(false)
2122
array(4) {

Zend/tests/each_003.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var_dump(each($a[1]));
1212

1313
?>
1414
--EXPECTF--
15+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
1516
array(4) {
1617
[1]=>
1718
array(0) {

Zend/zend_builtin_functions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,11 @@ ZEND_FUNCTION(each)
727727
return;
728728
}
729729

730+
if (!EG(each_deprecation_thrown)) {
731+
zend_error(E_DEPRECATED, "The each() function is deprecated. This message will be suppressed on further calls");
732+
EG(each_deprecation_thrown) = 1;
733+
}
734+
730735
target_hash = HASH_OF(array);
731736
if (!target_hash) {
732737
zend_error(E_WARNING,"Variable passed to each() is not an array or object");

Zend/zend_execute_API.c

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

188+
EG(each_deprecation_thrown) = 0;
189+
188190
EG(active) = 1;
189191
}
190192
/* }}} */

Zend/zend_globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ struct _zend_executor_globals {
230230
zend_function trampoline;
231231
zend_op call_trampoline_op;
232232

233+
zend_bool each_deprecation_thrown;
234+
233235
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
234236
};
235237

ext/mysqli/tests/bug42378.phpt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,18 @@ memory_limit=83886080
128128
}
129129
}
130130

131-
if (!empty($expected))
132-
reset($expected);
133-
while ((list($k, $v) = each($expected)) && mysqli_stmt_fetch($stmt)) {
134-
if (!empty($expected)) {
135-
if ($result !== $v) {
136-
printf("[%03d] Row %d - expecting %s/%s got %s/%s [%s] with %s - %s.\n",
137-
$offset + 8,
138-
$k,
139-
gettype($v), $v,
140-
gettype($result), $result,
141-
$order_by_col,
142-
$format, $sql);
143-
}
131+
foreach ($expected as $k => $v) {
132+
if (!mysqli_stmt_fetch($stmt)) {
133+
break;
134+
}
135+
if ($result !== $v) {
136+
printf("[%03d] Row %d - expecting %s/%s got %s/%s [%s] with %s - %s.\n",
137+
$offset + 8,
138+
$k,
139+
gettype($v), $v,
140+
gettype($result), $result,
141+
$order_by_col,
142+
$format, $sql);
144143
}
145144
}
146145

ext/mysqli/tests/mysqli_explain_metadata.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ if (!$IS_MYSQLND)
130130
}
131131
reset($fields);
132132
foreach ($fields_stmt as $fields_stmt_val) {
133-
list(,$fields_val) = each($fields);
133+
$fields_val = current($fields);
134+
next($fields);
134135
unset($fields_stmt_val->max_length);
135136
unset($fields_val->max_length);
136137
if ($fields_stmt_val != $fields_val) {

ext/mysqli/tests/mysqli_stmt_bind_result_format.phpt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ memory_limit=83886080
117117
return false;
118118
}
119119

120-
reset($expected);
121-
while ((list($k, $v) = each($expected)) && mysqli_stmt_fetch($stmt)) {
120+
foreach ($expected as $k => $v) {
121+
if (!mysqli_stmt_fetch($stmt)) {
122+
break;
123+
}
122124
if ($result !== $v) {
123125
printf("[%03d] Row %d - expecting %s/%s got %s/%s [%s] with %s - %s.\n",
124126
$offset + 8,
@@ -269,9 +271,10 @@ memory_limit=83886080
269271
break;
270272
}
271273

272-
reset($values);
273-
while (mysqli_stmt_fetch($stmt)) {
274-
list($exp_trend, $exp_targetport) = each($values);
274+
foreach ($values as $exp_trend => $exp_targetport) {
275+
if (!mysqli_stmt_fetch($stmt)) {
276+
break;
277+
}
275278
if ($targetport != $exp_targetport) {
276279
printf("[306] Values fetched from MySQL seem to be wrong, check manually\n");
277280
printf("%s/%s - %s/%s - '%s'\n", $trend, $exp_trend, $targetport, $exp_targetport, $format);
@@ -308,9 +311,10 @@ memory_limit=83886080
308311
break;
309312
}
310313

311-
reset($values);
312-
while ($stmt->fetch()) {
313-
list($exp_trend, $exp_targetport) = each($values);
314+
foreach ($values as $exp_trend => $exp_targetport) {
315+
if (!$stmt->fetch()) {
316+
break;
317+
}
314318
if ($targetport != $exp_targetport) {
315319
printf("[312] Values fetched from MySQL seem to be wrong, check manually\n");
316320
printf("%s/%s - %s/%s - '%s'\n", $trend, $exp_trend, $targetport, $exp_targetport, $format);
@@ -334,4 +338,4 @@ memory_limit=83886080
334338
require_once("clean_table.inc");
335339
?>
336340
--EXPECTF--
337-
done!
341+
done!

0 commit comments

Comments
 (0)