【问题标题】:Call to undefined function each() in php 8.1 [closed]在 php 8.1 中调用未定义的函数 each() [关闭]
【发布时间】:2023-01-28 09:03:54
【问题描述】:

我以前从来没有遇到过这个错误,但现在因为我运行的是 php 8.1,所以这段代码已经过时了。

// addslashes to vars if magic_quotes_gpc is off
// this is a security precaution to prevent someone
// trying to break out of a SQL statement.
//
//if( !@get_magic_quotes_gpc() ){
ini_set('magic_quotes_runtime', 0);{
    if( is_array($HTTP_GET_VARS) )
    {
        while( list($k, $v) = each($HTTP_GET_VARS) )
        {
            if( is_array($HTTP_GET_VARS[$k]) )
            {
                while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
                {
                    $HTTP_GET_VARS[$k][$k2] = addslashes($v2);
                }
                @reset($HTTP_GET_VARS[$k]);
            }
            else
            {
                $HTTP_GET_VARS[$k] = addslashes($v);

【问题讨论】:

  • php.net/manual/en/function.each.php 该功能已被删除。
  • 请不要将错误信息放在标题中
  • 没有任何提及魔法引语的东西真的应该在生产中了。 In November 2005 the core PHP developers decided that because of these problems, the magic quotes feature would be removed from PHP 6。所以 17 年前,该功能计划被删除。

标签: php each


【解决方案1】:

从 PHP 8.0 开始,each() 函数已被删除。 我建议用 foreach 语法替换每个函数。

foreach ($HTTP_GET_VARS as $k => $v) {
  $kv = [$k, $v];
}

【讨论】:

  • 真的只值得发表评论,然后关闭问题。这样的问题对别人没有用
猜你喜欢
  • 1970-01-01
  • 2014-01-24
  • 2012-10-23
  • 1970-01-01
  • 1970-01-01
  • 2022-06-14
  • 2015-05-29
  • 1970-01-01
相关资源
最近更新 更多