News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

The each() function is deprecated

Started by Ali_, April 19, 2019, 12:18:58 PM

Previous topic - Next topic

Ali_

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

Arantor

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)
Holder of controversial views, all of which my own.


Ali_

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?

Arantor

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...
Holder of controversial views, all of which my own.


Ali_

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.

GL700Wing

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):
// 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):
$dir = key($dirs);
$dest = current($dirs);

Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Sesquipedalian

2.0.17 officially fixes this. Please revert any manual changes you made, and then install 2.0.17.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Advertisement: