com php-src: Deprecate each(): Zend/tests/007.phpt Zend/tests/e ach_001.phpt Zend/tests/each_002.phpt Z end/tests/each_003.phpt
Zend/zend_builtin_funct ions.c Zend/zend_execute_API.c Zend/zend_globals .h ext/mysqli/tests/bug42378.phpt ext/mysqli/
tests/mysqli_explain_metadata.phpt ext/mysqli/tests/mys qli_stmt_bind_result_format.phpt ext/pcre/tests/bug 44191.phpt
ext/standard/tests/array/each.phpt ext/standard/tests/array/each_basic.phpt ext/standard/ te

From: Date: Fri, 03 Feb 2017 20:02:52 +0000
Subject: com php-src: Deprecate each(): Zend/tests/007.phpt Zend/tests/e ach_001.phpt Zend/tests/each_002.phpt Z end/tests/each_003.phpt
Zend/zend_builtin_funct ions.c Zend/zend_execute_API.c Zend/zend_globals .h ext/mysqli/tests/bug42378.phpt ext/mysqli/
tests/mysqli_explain_metadata.phpt ext/mysqli/tests/mys qli_stmt_bind_result_format.phpt ext/pcre/tests/bug 44191.phpt
ext/standard/tests/array/each.phpt ext/standard/tests/array/each_basic.phpt ext/standard/ te
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-97012@lists.php.net to get a copy of this message
Commit: 06a034016280435feb80eea4d674ca5688ab4c06 Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 2 Feb 2017 23:07:25 +0100 Parents: 6ba720662084306906e125d8f690146d7b86b303 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=06a034016280435feb80eea4d674ca5688ab4c06 Log: Deprecate each() Changed paths: M Zend/tests/007.phpt M Zend/tests/each_001.phpt M Zend/tests/each_002.phpt M Zend/tests/each_003.phpt M Zend/zend_builtin_functions.c M Zend/zend_execute_API.c M Zend/zend_globals.h M ext/mysqli/tests/bug42378.phpt M ext/mysqli/tests/mysqli_explain_metadata.phpt M ext/mysqli/tests/mysqli_stmt_bind_result_format.phpt M ext/pcre/tests/bug44191.phpt M ext/standard/tests/array/each.phpt M ext/standard/tests/array/each_basic.phpt M ext/standard/tests/array/each_variation1.phpt M ext/standard/tests/array/each_variation2.phpt M ext/standard/tests/array/each_variation3.phpt M ext/standard/tests/array/each_variation4.phpt M ext/standard/tests/array/each_variation5.phpt M ext/standard/tests/array/each_variation6.phpt M ext/xml/tests/xml001.phpt M ext/xml/tests/xml002.phpt M ext/xml/tests/xml003.phpt M ext/xml/tests/xml004.phpt M ext/xml/tests/xml_closures_001.phpt M run-tests.php M server-tests.php M tests/classes/iterators_006.phpt M tests/lang/031.phpt M tests/lang/each_binary_safety.phpt

diff --git a/Zend/tests/007.phpt b/Zend/tests/007.phpt index 3fff2b8..f8e5b99 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 06ab52a..f2cae3d 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 31b749e..5454f5c 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 fbd5455..d0038c0 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 397a043..91bf0ee 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 d183e2b..c3c7920 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 9c56ca9..083875f 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 b3fd7ca..f3bbe34 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 fc1f9db..8f4a7cc 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 dee5a7e..68ec601 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 52b4490..73fc29c 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 974808c..f1b6f76 100644 Binary files a/ext/standard/tests/array/each.phpt and b/ext/standard/tests/array/each.phpt differ diff --git a/ext/standard/tests/array/each_basic.phpt b/ext/standard/tests/array/each_basic.phpt index 350b40f..b12b4c1 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 0afef31..becdfc4 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 3f7211c..73b1ba2 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 b31ddc6..3756156 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 535ae29..14b5536 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 941ad5e..b6c3953 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 445d63f..ba0f265 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 9c03b55..987991e 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 ce547e8..f563199 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 6b0c3f5..9734311 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 245a93f..a9e68e1 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 37df254..defffbb 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 32e68ca..1d57353 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 9178424..6e1620f 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 8017a8a..564f15d 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 b2d1e63..134df03 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 bb13534..37b18b3 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
« previous php.cvs (#97012) next »