Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Ali_ on April 19, 2019, 12:18:58 PM

Title: The each() function is deprecated
Post by: Ali_ on April 19, 2019, 12:18:58 PM
I have one more error, it's only on one line.  It tells me that the each() function is deprecated.  How can I re-write this so that I get rid of the error?

https://www.waygook.org/index.php?topic=130
8192: The each() function is deprecated. This message will be suppressed on further calls
File: /var/www/Sources/Load.php
Line: 1604

Here's the code:


// Hmm... check #2 - is it just different by a www?  Send them to the correct place!!
if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
{
// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
if (empty($_GET))
redirectexit('wwwRedirect');
else
{
list ($k, $v) = each($_GET);

if ($k != 'wwwRedirect')
redirectexit('wwwRedirect;' . $k . '=' . $v);
}
}
Title: Re: The each() function is deprecated
Post by: Arantor on April 19, 2019, 12:21:25 PM
You're running PHP 7.2. SMF 2.0 does not support PHP 7.2 properly. (I'm amazed you're not getting more errors)
Title: Re: The each() function is deprecated
Post by: Ali_ on April 19, 2019, 12:43:11 PM
I know, but I should be able to re-write that line of code to work without errors.  Can anyone give me a hand with it?
Title: Re: The each() function is deprecated
Post by: Arantor on April 19, 2019, 12:58:26 PM
You could look at the 2.1 equivalent...

// Hmm... check #2 - is it just different by a www?  Send them to the correct place!!
if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
{
// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
if (empty($_GET))
redirectexit('wwwRedirect');
else
{
$k = key($_GET);
$v = current($_GET);
if ($k != 'wwwRedirect')
redirectexit('wwwRedirect;' . $k . '=' . $v);
}
}


But you're only going to have more and more problems because SMF 2.0 will not be upgraded officially to support PHP 7.2...
Title: Re: The each() function is deprecated
Post by: Ali_ on April 19, 2019, 04:39:06 PM
That took care of it, thank you :)

Vbgamer posted this link ( https://www.smfhacks.com/index.php?action=downloads;sa=view;id=215 ) for the create_function() problem, that got rid of all my errors.  I am not going to worry too much about upgrading further with 2.0.  Going to wait on 2.1 to be released and upgrade to that if it's possible.
Title: Re: The each() function is deprecated
Post by: GL700Wing on December 28, 2019, 11:47:01 PM
A few hours ago I upgraded to 2.0.16 and changed to PHP 7.2 and even though I haven't yet seen this error (and don't know if I will) I've found two default files that are still using each():

In ./Sources/Load.php:
Find:
// Hmm... check #2 - is it just different by a www?  Send them to the correct place!!
if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
{
// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
if (empty($_GET))
redirectexit('wwwRedirect');
else
{
list ($k, $v) = each($_GET);

if ($k != 'wwwRedirect')
redirectexit('wwwRedirect;' . $k . '=' . $v);
}
}

Replace With (as per Arantor's post (https://www.simplemachines.org/community/index.php?topic=567315.msg4016788#msg4016788)):
// Hmm... check #2 - is it just different by a www?  Send them to the correct place!!
if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
{
// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
if (empty($_GET))
redirectexit('wwwRedirect');
else
{
$k = key($_GET);
$v = current($_GET);
if ($k != 'wwwRedirect')
redirectexit('wwwRedirect;' . $k . '=' . $v);
}
}


In ./Sources/Subs-Package.php:
Find:
list ($dir, $dest) = each($dirs);
Replace With (using same logic as Arantor's post (https://www.simplemachines.org/community/index.php?topic=567315.msg4016788#msg4016788)):
$dir = key($dirs);
$dest = current($dirs);

Title: Re: The each() function is deprecated
Post by: Sesquipedalian on December 31, 2019, 12:52:15 AM
2.0.17 officially fixes this. Please revert any manual changes you made, and then install 2.0.17.