XF 1.5 Upgrade issue: Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead

SchmitzIT

Well-known member
Hi,

I'm moving a forum between hosts. The forum currently is on xf 1.5. The old server ran PHP 5.6, where the earliest version offered by the new host is 7.4.

I received an error regarding a deprecated function and grabbed the latest update for the forum (xf 1.5 24). However, the issue persists. I cannot downgrade further, and currently the domain name points to the new server, so I cannot perform the upgrade on the forum anymore.

The file it points to containing/throwing the error is /library/Zend/Registry.php:206, which has the following line in it:

return array_key_exists($index, $this);

PHP documentation suggests replacing with isset or property_exists. How would I rewrite the line above to allow me to continue the forum upgrade, please?

Thanks!

/Peter
 
Doing an upgrade and changing PHP versions simultaneously is always going to be a challenge, especially when you're constrained by a lower limit.

Officially our advice is to perform this upgrade using PHP 7.0 - 7.3, but in lieu of that, hopefully this is the only change required:

Code:
return property_exists($this, $index);
 
Hi Chris. Thanks for your reply, and I hope you're doing well :)

Unfortunately that ends up with my server throwing a configuration error:

Internal Server Error​

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at support@one.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Php errors aren't showing. I tried asking the host to downgrade PHP, but they said it has been removed from the server altogether. I'm not sure how to proceed with this. The odd thing is that the Zend File even in the latest version uses the deprecated function.

I guess my only alternative now is to perform the upgrade locally somehow, or revert everything back to the old host, and try again next weekend.
 
Just want to check; the change isn't just changing array_key_exists to property_exists. Somewhat confusingly, the arguments need to swap places too. So worth making sure you changed the code to exactly as written.

An alternative is to try isset which would look like:

Code:
return isset($this[$index]);

If it's still falling over it may just mean there is an incompatibility elsewhere that you're running into but without any error messages (worth checking the php-fpm logs if possible) it's hard to debug it further so upgrading offline or at the old host may be required.
 
Thanks, Chris. I copy/pasted the original line you supplied, so the arguments should have been in the correct order. I also tried switching them around, just in case, but that didn't work, either. Prior, I also tried explicitly returning false (which throws another error), or true (which somehow didn't work at all).

Isset also didn't do the trick. I guess there are other/more issues. Somehow after going back to the original array_key_exists, it now throws yet another error:

Deprecated: Array and string offset access syntax with curly braces is deprecated in /library/Lgpl/utf8.php on line 47

I guess I'll switch back to the old server, and try doing the upgrade there.
 
@Chris D - We reverted back to the old server with PHP 5.6. I upgraded the forum to XF 1.5.24, and grabbed the files as well as the database. Anything else I should try before trying to move everything to the new server again? Did I overlook anything, or need to try anything else in order to mitigate risk as much as possible?

Thanks :)
 
Back
Top Bottom