Advertisement:

Author Topic: The each() function is deprecated  (Read 210 times)

Offline Ali_

  • Semi-Newbie
  • *
  • Posts: 62
The each() function is deprecated
« 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:

Code: [Select]
// 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);
}
}

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 70,939
    • StoryBB/StoryBB on GitHub
Re: The each() function is deprecated
« Reply #1 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)
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Ali_

  • Semi-Newbie
  • *
  • Posts: 62
Re: The each() function is deprecated
« Reply #2 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?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 70,939
    • StoryBB/StoryBB on GitHub
Re: The each() function is deprecated
« Reply #3 on: April 19, 2019, 12:58:26 PM »
You could look at the 2.1 equivalent...

Code: [Select]
// 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...
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Ali_

  • Semi-Newbie
  • *
  • Posts: 62
Re: The each() function is deprecated
« Reply #4 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.