1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Deprecate each()

This commit is contained in:
Nikita Popov
2017-02-02 23:07:25 +01:00
parent 6ba7206620
commit 06a0340162
29 changed files with 79 additions and 43 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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");

View File

@@ -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;
}
/* }}} */

View File

@@ -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];
};

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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!
done!

View File

@@ -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;
}
?>

Binary file not shown.

View File

@@ -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
Done

View File

@@ -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

View File

@@ -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
Done

View File

@@ -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
Done

View File

@@ -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"

View File

@@ -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
Done

View File

@@ -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
Done

View File

@@ -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\"";
}
}

View File

@@ -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\"";
}
}

View File

@@ -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\"";
}
}

View File

@@ -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\"";
}
}

View File

@@ -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\"";
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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