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

+2
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

+2
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

+1
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

+1
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

+5
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

+2
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

+2
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

+12-13
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

+2-1
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

+13-9
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!

ext/pcre/tests/bug44191.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ $array = range(1, 10);
77

88
preg_grep('/asdf/', $array);
99

10-
while (list($x) = each($array)) {
11-
print $x;
10+
foreach ($array as $k => $v) {
11+
print $k;
1212
}
1313

1414
?>

ext/standard/tests/array/each.phpt

114 Bytes
Binary file not shown.

ext/standard/tests/array/each_basic.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ array(4) {
4646
}
4747

4848
-- Initial position: --
49+
50+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
4951
array(4) {
5052
[1]=>
5153
int(1)
@@ -71,4 +73,4 @@ array(4) {
7173

7274
-- Passed the end of array: --
7375
bool(false)
74-
Done
76+
Done

ext/standard/tests/array/each_variation1.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ echo "Done";
101101

102102
-- Iteration 1 --
103103

104+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
105+
104106
Warning: Variable passed to each() is not an array or object in %s on line %d
105107
NULL
106108

ext/standard/tests/array/each_variation2.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ echo "Done";
122122
*** Testing each() : usage variations ***
123123

124124
-- Iteration 1: int data --
125+
126+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
125127
array(4) {
126128
[1]=>
127129
int(0)
@@ -245,4 +247,4 @@ array(4) {
245247
["key"]=>
246248
int(0)
247249
}
248-
Done
250+
Done

ext/standard/tests/array/each_variation3.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ echo "Done";
108108
*** Testing each() : usage variations ***
109109

110110
-- Iteration 1: int data --
111+
112+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
111113
array(4) {
112114
[1]=>
113115
string(4) "zero"
@@ -250,4 +252,4 @@ array(4) {
250252
["key"]=>
251253
string(0) ""
252254
}
253-
Done
255+
Done

ext/standard/tests/array/each_variation4.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ echo "Done";
3535

3636
-- Array made up of referenced variables: --
3737
-- Call each until at the end of the array: --
38+
39+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
3840
array(4) {
3941
[1]=>
4042
string(3) "foo"

ext/standard/tests/array/each_variation5.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ echo "Done";
3737
*** Testing each() : usage variations ***
3838

3939
-- Pass each() a two-dimensional array --
40+
41+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
4042
array(4) {
4143
[1]=>
4244
string(4) "zero"
@@ -93,4 +95,4 @@ array(4) {
9395
["key"]=>
9496
int(0)
9597
}
96-
Done
98+
Done

ext/standard/tests/array/each_variation6.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ echo "Done";
3535
0 => zero
3636

3737
-- Call to each(): --
38+
39+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
3840
array(4) {
3941
[1]=>
4042
string(4) "zero"
@@ -48,4 +50,4 @@ array(4) {
4850

4951
-- New position: --
5052
1 => one
51-
Done
53+
Done

ext/xml/tests/xml001.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function startElement($parser, $name, $attribs)
3535
{
3636
print '{'.$name;
3737
if (sizeof($attribs)) {
38-
while (list($k, $v) = each($attribs)) {
38+
foreach ($attribs as $k => $v) {
3939
print " $k=\"$v\"";
4040
}
4141
}

ext/xml/tests/xml002.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class myclass
1515
{
1616
print '{'.$name;
1717
if (sizeof($attribs)) {
18-
while (list($k, $v) = each($attribs)) {
18+
foreach ($attribs as $k => $v) {
1919
print " $k=\"$v\"";
2020
}
2121
}

ext/xml/tests/xml003.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class myclass
1515
{
1616
print '{'.$name;
1717
if (sizeof($attribs)) {
18-
while (list($k, $v) = each($attribs)) {
18+
foreach ($attribs as $k => $v) {
1919
print " $k=\"$v\"";
2020
}
2121
}

ext/xml/tests/xml004.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function start_element($xp, $elem, $attribs)
2727
{
2828
print "<$elem";
2929
if (sizeof($attribs)) {
30-
while (list($k, $v) = each($attribs)) {
30+
foreach ($attribs as $k => $v) {
3131
print " $k=\"$v\"";
3232
}
3333
}

ext/xml/tests/xml_closures_001.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $start_element = function ($xp, $elem, $attribs)
1010
{
1111
print "<$elem";
1212
if (sizeof($attribs)) {
13-
while (list($k, $v) = each($attribs)) {
13+
foreach ($attribs as $k => $v) {
1414
print " $k=\"$v\"";
1515
}
1616
}

run-tests.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,7 @@ function compute_summary()
24152415
$sum_results['SKIPPED'] += $ignored_by_ext;
24162416
$percent_results = array();
24172417

2418-
while (list($v, $n) = each($sum_results)) {
2418+
foreach ($sum_results as $v => $n) {
24192419
$percent_results[$v] = (100.0 * $n) / $n_total;
24202420
}
24212421
}

server-tests.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ function summarizeResults()
901901
}
902902
$sum_results['SKIPPED'] += $this->ignored_by_ext;
903903
$percent_results = array();
904-
while (list($v,$n) = each($sum_results)) {
904+
foreach ($sum_results as $v => $n) {
905905
$percent_results[$v] = (100.0 * $n) / $n_total;
906906
}
907907

tests/classes/iterators_006.phpt

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ class ai implements Iterator {
2929
}
3030

3131
function next() {
32-
list($this->key, $this->current) = each($this->array);
33-
// list($key, $current) = each($this->array);
34-
// $this->key = $key;
35-
// $this->current = $current;
32+
$this->key = key($this->array);
33+
$this->current = current($this->array);
34+
next($this->array);
3635
}
3736
}
3837

tests/lang/031.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ while(list(,$o) = each($arrayOuter)){
4949
reset($arrayOuter);
5050
reset($arrayInner);
5151
?>
52-
--EXPECT--
52+
--EXPECTF--
5353
Correct - with inner loop reset.
54+
55+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
5456
inloop 0 for key1
5557
inloop 1 for key1
5658
inloop 0 for key2

tests/lang/each_binary_safety.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ while (list($key, $val) = each($arr)) {
99
echo urlencode($key), ' => ', urlencode($val), "\n";
1010
}
1111
?>
12-
--EXPECT--
12+
--EXPECTF--
13+
14+
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
1315
7: foo%00bar => foo%00bar

0 commit comments

Comments
 (0)