summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-02-02 23:07:25 +0100
committerNikita Popov <nikita.ppv@gmail.com>2017-02-03 21:02:52 +0100
commit06a034016280435feb80eea4d674ca5688ab4c06 (patch)
treeb9860ce0cacadef78cf3ed1fc250f3048aee4793
parent6ba720662084306906e125d8f690146d7b86b303 (diff)
downloadphp-git-06a034016280435feb80eea4d674ca5688ab4c06.tar.gz
Deprecate each()
-rw-r--r--Zend/tests/007.phpt2
-rw-r--r--Zend/tests/each_001.phpt2
-rw-r--r--Zend/tests/each_002.phpt1
-rw-r--r--Zend/tests/each_003.phpt1
-rw-r--r--Zend/zend_builtin_functions.c5
-rw-r--r--Zend/zend_execute_API.c2
-rw-r--r--Zend/zend_globals.h2
-rw-r--r--ext/mysqli/tests/bug42378.phpt25
-rw-r--r--ext/mysqli/tests/mysqli_explain_metadata.phpt3
-rw-r--r--ext/mysqli/tests/mysqli_stmt_bind_result_format.phpt22
-rw-r--r--ext/pcre/tests/bug44191.phpt4
-rw-r--r--ext/standard/tests/array/each.phptbin9574 -> 9688 bytes
-rw-r--r--ext/standard/tests/array/each_basic.phpt4
-rw-r--r--ext/standard/tests/array/each_variation1.phpt2
-rw-r--r--ext/standard/tests/array/each_variation2.phpt4
-rw-r--r--ext/standard/tests/array/each_variation3.phpt4
-rw-r--r--ext/standard/tests/array/each_variation4.phpt2
-rw-r--r--ext/standard/tests/array/each_variation5.phpt4
-rw-r--r--ext/standard/tests/array/each_variation6.phpt4
-rw-r--r--ext/xml/tests/xml001.phpt2
-rw-r--r--ext/xml/tests/xml002.phpt2
-rw-r--r--ext/xml/tests/xml003.phpt2
-rw-r--r--ext/xml/tests/xml004.phpt2
-rw-r--r--ext/xml/tests/xml_closures_001.phpt2
-rwxr-xr-xrun-tests.php2
-rwxr-xr-xserver-tests.php2
-rw-r--r--tests/classes/iterators_006.phpt7
-rw-r--r--tests/lang/031.phpt4
-rw-r--r--tests/lang/each_binary_safety.phpt4
29 files changed, 79 insertions, 43 deletions
diff --git a/Zend/tests/007.phpt b/Zend/tests/007.phpt
index 3fff2b830a..f8e5b99a0e 100644
--- a/Zend/tests/007.phpt
+++ b/Zend/tests/007.phpt
@@ -25,6 +25,8 @@ echo "Done\n";
Warning: each() expects exactly 1 parameter, 0 given in %s on line %d
NULL
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
+
Warning: Variable passed to each() is not an array or object in %s on line %d
NULL
diff --git a/Zend/tests/each_001.phpt b/Zend/tests/each_001.phpt
index 06ab52a9c8..f2cae3d875 100644
--- a/Zend/tests/each_001.phpt
+++ b/Zend/tests/each_001.phpt
@@ -7,4 +7,6 @@ each($foo);
?>
--EXPECTF--
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
+
Warning: Variable passed to each() is not an array or object in %s on line %d
diff --git a/Zend/tests/each_002.phpt b/Zend/tests/each_002.phpt
index 31b749e5fd..5454f5ce0f 100644
--- a/Zend/tests/each_002.phpt
+++ b/Zend/tests/each_002.phpt
@@ -16,6 +16,7 @@ var_dump(each($a));
?>
--EXPECTF--
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
bool(false)
bool(false)
array(4) {
diff --git a/Zend/tests/each_003.phpt b/Zend/tests/each_003.phpt
index fbd54550fc..d0038c0561 100644
--- a/Zend/tests/each_003.phpt
+++ b/Zend/tests/each_003.phpt
@@ -12,6 +12,7 @@ var_dump(each($a[1]));
?>
--EXPECTF--
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
array(4) {
[1]=>
array(0) {
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 397a043a5b..91bf0ee7b0 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -727,6 +727,11 @@ ZEND_FUNCTION(each)
return;
}
+ if (!EG(each_deprecation_thrown)) {
+ zend_error(E_DEPRECATED, "The each() function is deprecated. This message will be suppressed on further calls");
+ EG(each_deprecation_thrown) = 1;
+ }
+
target_hash = HASH_OF(array);
if (!target_hash) {
zend_error(E_WARNING,"Variable passed to each() is not an array or object");
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index d183e2b27d..c3c7920019 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -185,6 +185,8 @@ void init_executor(void) /* {{{ */
EG(ht_iterators) = EG(ht_iterators_slots);
memset(EG(ht_iterators), 0, sizeof(EG(ht_iterators_slots)));
+ EG(each_deprecation_thrown) = 0;
+
EG(active) = 1;
}
/* }}} */
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index 9c56ca998d..083875fc2c 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -230,6 +230,8 @@ struct _zend_executor_globals {
zend_function trampoline;
zend_op call_trampoline_op;
+ zend_bool each_deprecation_thrown;
+
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
};
diff --git a/ext/mysqli/tests/bug42378.phpt b/ext/mysqli/tests/bug42378.phpt
index b3fd7ca524..f3bbe346fa 100644
--- a/ext/mysqli/tests/bug42378.phpt
+++ b/ext/mysqli/tests/bug42378.phpt
@@ -128,19 +128,18 @@ memory_limit=83886080
}
}
- if (!empty($expected))
- reset($expected);
- while ((list($k, $v) = each($expected)) && mysqli_stmt_fetch($stmt)) {
- if (!empty($expected)) {
- if ($result !== $v) {
- printf("[%03d] Row %d - expecting %s/%s got %s/%s [%s] with %s - %s.\n",
- $offset + 8,
- $k,
- gettype($v), $v,
- gettype($result), $result,
- $order_by_col,
- $format, $sql);
- }
+ foreach ($expected as $k => $v) {
+ if (!mysqli_stmt_fetch($stmt)) {
+ break;
+ }
+ if ($result !== $v) {
+ printf("[%03d] Row %d - expecting %s/%s got %s/%s [%s] with %s - %s.\n",
+ $offset + 8,
+ $k,
+ gettype($v), $v,
+ gettype($result), $result,
+ $order_by_col,
+ $format, $sql);
}
}
diff --git a/ext/mysqli/tests/mysqli_explain_metadata.phpt b/ext/mysqli/tests/mysqli_explain_metadata.phpt
index fc1f9dbe49..8f4a7cc8c5 100644
--- a/ext/mysqli/tests/mysqli_explain_metadata.phpt
+++ b/ext/mysqli/tests/mysqli_explain_metadata.phpt
@@ -130,7 +130,8 @@ if (!$IS_MYSQLND)
}
reset($fields);
foreach ($fields_stmt as $fields_stmt_val) {
- list(,$fields_val) = each($fields);
+ $fields_val = current($fields);
+ next($fields);
unset($fields_stmt_val->max_length);
unset($fields_val->max_length);
if ($fields_stmt_val != $fields_val) {
diff --git a/ext/mysqli/tests/mysqli_stmt_bind_result_format.phpt b/ext/mysqli/tests/mysqli_stmt_bind_result_format.phpt
index dee5a7e0f0..68ec601e10 100644
--- a/ext/mysqli/tests/mysqli_stmt_bind_result_format.phpt
+++ b/ext/mysqli/tests/mysqli_stmt_bind_result_format.phpt
@@ -117,8 +117,10 @@ memory_limit=83886080
return false;
}
- reset($expected);
- while ((list($k, $v) = each($expected)) && mysqli_stmt_fetch($stmt)) {
+ foreach ($expected as $k => $v) {
+ if (!mysqli_stmt_fetch($stmt)) {
+ break;
+ }
if ($result !== $v) {
printf("[%03d] Row %d - expecting %s/%s got %s/%s [%s] with %s - %s.\n",
$offset + 8,
@@ -269,9 +271,10 @@ memory_limit=83886080
break;
}
- reset($values);
- while (mysqli_stmt_fetch($stmt)) {
- list($exp_trend, $exp_targetport) = each($values);
+ foreach ($values as $exp_trend => $exp_targetport) {
+ if (!mysqli_stmt_fetch($stmt)) {
+ break;
+ }
if ($targetport != $exp_targetport) {
printf("[306] Values fetched from MySQL seem to be wrong, check manually\n");
printf("%s/%s - %s/%s - '%s'\n", $trend, $exp_trend, $targetport, $exp_targetport, $format);
@@ -308,9 +311,10 @@ memory_limit=83886080
break;
}
- reset($values);
- while ($stmt->fetch()) {
- list($exp_trend, $exp_targetport) = each($values);
+ foreach ($values as $exp_trend => $exp_targetport) {
+ if (!$stmt->fetch()) {
+ break;
+ }
if ($targetport != $exp_targetport) {
printf("[312] Values fetched from MySQL seem to be wrong, check manually\n");
printf("%s/%s - %s/%s - '%s'\n", $trend, $exp_trend, $targetport, $exp_targetport, $format);
@@ -334,4 +338,4 @@ memory_limit=83886080
require_once("clean_table.inc");
?>
--EXPECTF--
-done! \ No newline at end of file
+done!
diff --git a/ext/pcre/tests/bug44191.phpt b/ext/pcre/tests/bug44191.phpt
index 52b449091b..73fc29cd90 100644
--- a/ext/pcre/tests/bug44191.phpt
+++ b/ext/pcre/tests/bug44191.phpt
@@ -7,8 +7,8 @@ $array = range(1, 10);
preg_grep('/asdf/', $array);
-while (list($x) = each($array)) {
- print $x;
+foreach ($array as $k => $v) {
+ print $k;
}
?>
diff --git a/ext/standard/tests/array/each.phpt b/ext/standard/tests/array/each.phpt
index 974808c08c..f1b6f76ea6 100644
--- a/ext/standard/tests/array/each.phpt
+++ b/ext/standard/tests/array/each.phpt
Binary files differ
diff --git a/ext/standard/tests/array/each_basic.phpt b/ext/standard/tests/array/each_basic.phpt
index 350b40f9a3..b12b4c19f7 100644
--- a/ext/standard/tests/array/each_basic.phpt
+++ b/ext/standard/tests/array/each_basic.phpt
@@ -46,6 +46,8 @@ array(4) {
}
-- Initial position: --
+
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
array(4) {
[1]=>
int(1)
@@ -71,4 +73,4 @@ array(4) {
-- Passed the end of array: --
bool(false)
-Done \ No newline at end of file
+Done
diff --git a/ext/standard/tests/array/each_variation1.phpt b/ext/standard/tests/array/each_variation1.phpt
index 0afef31432..becdfc4545 100644
--- a/ext/standard/tests/array/each_variation1.phpt
+++ b/ext/standard/tests/array/each_variation1.phpt
@@ -101,6 +101,8 @@ echo "Done";
-- Iteration 1 --
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
+
Warning: Variable passed to each() is not an array or object in %s on line %d
NULL
diff --git a/ext/standard/tests/array/each_variation2.phpt b/ext/standard/tests/array/each_variation2.phpt
index 3f7211c89c..73b1ba2746 100644
--- a/ext/standard/tests/array/each_variation2.phpt
+++ b/ext/standard/tests/array/each_variation2.phpt
@@ -122,6 +122,8 @@ echo "Done";
*** Testing each() : usage variations ***
-- Iteration 1: int data --
+
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
array(4) {
[1]=>
int(0)
@@ -245,4 +247,4 @@ array(4) {
["key"]=>
int(0)
}
-Done \ No newline at end of file
+Done
diff --git a/ext/standard/tests/array/each_variation3.phpt b/ext/standard/tests/array/each_variation3.phpt
index b31ddc61b4..375615643f 100644
--- a/ext/standard/tests/array/each_variation3.phpt
+++ b/ext/standard/tests/array/each_variation3.phpt
@@ -108,6 +108,8 @@ echo "Done";
*** Testing each() : usage variations ***
-- Iteration 1: int data --
+
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
array(4) {
[1]=>
string(4) "zero"
@@ -250,4 +252,4 @@ array(4) {
["key"]=>
string(0) ""
}
-Done \ No newline at end of file
+Done
diff --git a/ext/standard/tests/array/each_variation4.phpt b/ext/standard/tests/array/each_variation4.phpt
index 535ae297d1..14b5536135 100644
--- a/ext/standard/tests/array/each_variation4.phpt
+++ b/ext/standard/tests/array/each_variation4.phpt
@@ -35,6 +35,8 @@ echo "Done";
-- Array made up of referenced variables: --
-- Call each until at the end of the array: --
+
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
array(4) {
[1]=>
string(3) "foo"
diff --git a/ext/standard/tests/array/each_variation5.phpt b/ext/standard/tests/array/each_variation5.phpt
index 941ad5e3ac..b6c39538a3 100644
--- a/ext/standard/tests/array/each_variation5.phpt
+++ b/ext/standard/tests/array/each_variation5.phpt
@@ -37,6 +37,8 @@ echo "Done";
*** Testing each() : usage variations ***
-- Pass each() a two-dimensional array --
+
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
array(4) {
[1]=>
string(4) "zero"
@@ -93,4 +95,4 @@ array(4) {
["key"]=>
int(0)
}
-Done \ No newline at end of file
+Done
diff --git a/ext/standard/tests/array/each_variation6.phpt b/ext/standard/tests/array/each_variation6.phpt
index 445d63f318..ba0f2657c8 100644
--- a/ext/standard/tests/array/each_variation6.phpt
+++ b/ext/standard/tests/array/each_variation6.phpt
@@ -35,6 +35,8 @@ echo "Done";
0 => zero
-- Call to each(): --
+
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
array(4) {
[1]=>
string(4) "zero"
@@ -48,4 +50,4 @@ array(4) {
-- New position: --
1 => one
-Done \ No newline at end of file
+Done
diff --git a/ext/xml/tests/xml001.phpt b/ext/xml/tests/xml001.phpt
index 9c03b553cc..987991e8a8 100644
--- a/ext/xml/tests/xml001.phpt
+++ b/ext/xml/tests/xml001.phpt
@@ -35,7 +35,7 @@ function startElement($parser, $name, $attribs)
{
print '{'.$name;
if (sizeof($attribs)) {
- while (list($k, $v) = each($attribs)) {
+ foreach ($attribs as $k => $v) {
print " $k=\"$v\"";
}
}
diff --git a/ext/xml/tests/xml002.phpt b/ext/xml/tests/xml002.phpt
index ce547e8acc..f56319932e 100644
--- a/ext/xml/tests/xml002.phpt
+++ b/ext/xml/tests/xml002.phpt
@@ -15,7 +15,7 @@ class myclass
{
print '{'.$name;
if (sizeof($attribs)) {
- while (list($k, $v) = each($attribs)) {
+ foreach ($attribs as $k => $v) {
print " $k=\"$v\"";
}
}
diff --git a/ext/xml/tests/xml003.phpt b/ext/xml/tests/xml003.phpt
index 6b0c3f5c5a..973431104b 100644
--- a/ext/xml/tests/xml003.phpt
+++ b/ext/xml/tests/xml003.phpt
@@ -15,7 +15,7 @@ class myclass
{
print '{'.$name;
if (sizeof($attribs)) {
- while (list($k, $v) = each($attribs)) {
+ foreach ($attribs as $k => $v) {
print " $k=\"$v\"";
}
}
diff --git a/ext/xml/tests/xml004.phpt b/ext/xml/tests/xml004.phpt
index 245a93fc10..a9e68e103f 100644
--- a/ext/xml/tests/xml004.phpt
+++ b/ext/xml/tests/xml004.phpt
@@ -27,7 +27,7 @@ function start_element($xp, $elem, $attribs)
{
print "<$elem";
if (sizeof($attribs)) {
- while (list($k, $v) = each($attribs)) {
+ foreach ($attribs as $k => $v) {
print " $k=\"$v\"";
}
}
diff --git a/ext/xml/tests/xml_closures_001.phpt b/ext/xml/tests/xml_closures_001.phpt
index 37df254190..defffbb2ae 100644
--- a/ext/xml/tests/xml_closures_001.phpt
+++ b/ext/xml/tests/xml_closures_001.phpt
@@ -10,7 +10,7 @@ $start_element = function ($xp, $elem, $attribs)
{
print "<$elem";
if (sizeof($attribs)) {
- while (list($k, $v) = each($attribs)) {
+ foreach ($attribs as $k => $v) {
print " $k=\"$v\"";
}
}
diff --git a/run-tests.php b/run-tests.php
index 32e68cad47..1d573530fb 100755
--- a/run-tests.php
+++ b/run-tests.php
@@ -2415,7 +2415,7 @@ function compute_summary()
$sum_results['SKIPPED'] += $ignored_by_ext;
$percent_results = array();
- while (list($v, $n) = each($sum_results)) {
+ foreach ($sum_results as $v => $n) {
$percent_results[$v] = (100.0 * $n) / $n_total;
}
}
diff --git a/server-tests.php b/server-tests.php
index 91784249f5..6e1620f1a8 100755
--- a/server-tests.php
+++ b/server-tests.php
@@ -901,7 +901,7 @@ class testHarness {
}
$sum_results['SKIPPED'] += $this->ignored_by_ext;
$percent_results = array();
- while (list($v,$n) = each($sum_results)) {
+ foreach ($sum_results as $v => $n) {
$percent_results[$v] = (100.0 * $n) / $n_total;
}
diff --git a/tests/classes/iterators_006.phpt b/tests/classes/iterators_006.phpt
index 8017a8a360..564f15de54 100644
--- a/tests/classes/iterators_006.phpt
+++ b/tests/classes/iterators_006.phpt
@@ -29,10 +29,9 @@ class ai implements Iterator {
}
function next() {
- list($this->key, $this->current) = each($this->array);
-// list($key, $current) = each($this->array);
-// $this->key = $key;
-// $this->current = $current;
+ $this->key = key($this->array);
+ $this->current = current($this->array);
+ next($this->array);
}
}
diff --git a/tests/lang/031.phpt b/tests/lang/031.phpt
index b2d1e631ec..134df03684 100644
--- a/tests/lang/031.phpt
+++ b/tests/lang/031.phpt
@@ -49,8 +49,10 @@ while(list(,$o) = each($arrayOuter)){
reset($arrayOuter);
reset($arrayInner);
?>
---EXPECT--
+--EXPECTF--
Correct - with inner loop reset.
+
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
inloop 0 for key1
inloop 1 for key1
inloop 0 for key2
diff --git a/tests/lang/each_binary_safety.phpt b/tests/lang/each_binary_safety.phpt
index bb13534546..37b18b32c7 100644
--- a/tests/lang/each_binary_safety.phpt
+++ b/tests/lang/each_binary_safety.phpt
@@ -9,5 +9,7 @@ while (list($key, $val) = each($arr)) {
echo urlencode($key), ' => ', urlencode($val), "\n";
}
?>
---EXPECT--
+--EXPECTF--
+
+Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
7: foo%00bar => foo%00bar