Home > OS >  Call to undefined function each() in php 8.1
Call to undefined function each() in php 8.1

Time:11-18

I've never got this error before but now since I am running php 8.1 then this piece of code is obsolete.

// 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);

CodePudding user response:

The each function has been removed as of PHP 8.0. I would recommend replacing the each function with the foreach function.

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