MyBB Community Forums

Full Version: 1.8.33 upgrade and PHP 8 warnings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have successfully upgraded production forum to 1.8.33. Using PHP 7.4 without problems.
After cloning production server for testing purposes using PHP 8.0.27, I am going through and finding warnings. Most occur in plugins.

If I create a post containing a youtube video with a url in the form of https://youtu.be/YfdLh0MHqKw, I get the following messages.
Warning [2] Undefined array key "fragment" - Line: 1494 - File: inc/class_parser.php PHP 8.0.27 (Linux)
Warning [2] Undefined array key "query" - Line: 1505 - File: inc/class_parser.php PHP 8.0.27 (Linux)
Warning [2] Undefined array key 1 - Line: 1510 - File: inc/class_parser.php PHP 8.0.27 (Linux)
Warning [2] Undefined array key 0 - Line: 1587 - File: inc/class_parser.php PHP 8.0.27 (Linux)
Warning [2] Undefined array key "v" - Line: 1591 - File: inc/class_parser.php PHP 8.0.27 (Linux)

I note that line 1485 of inc/class_parser.php uses a native PHP function in the function mycode_parse_video() starting line 1470.
$parsed_url = @parse_url(urldecode($url));

The url does not contain a fragment in line 1494, or a query in line 1505, hence there are no $input keys in line 1510, unable to test the empty fragment array in 1587, as well as testing the $input array in 1591.

First, what purpose does line 1480 have? I think it is superfluous. Defined but not used.
1480 $bbdomain = parse_url($mybb->settings['bburl'], PHP_URL_HOST);

I made several modifications to the mycode_parse_video() function, although unable to post code in its entirety. Community only permits a single video per post, and cannot distinguish examples in comments.

Now, all three variations display.
youtu[dot]be/YfdLh0MHqKw
www[dot]youtube[dot]com/watch?v=YfdLh0MHqKw
www[dot]youtube[dot]com/watch#!v=YfdLh0MHqKw

I've had to obfuscate URLs used as explanation, including the ones used as examples in the code comments.

lines altered as below. By adding three lines, last two line numbers are pushed down.
1494 		if(array_key_exists('fragment', $parsed_url))	//core edit fixes error if no 'fragment' in $parsed_url
1499		if(array_key_exists('query', $parsed_url))	//core edit added to fix if no 'query' in $parsed_url
1500		{						//core edit added for if statement
1516		}						//core edit added for if statement
1590				if(isset($fragments[0]))	//core edit to fix when $fragments is empty
1594				elseif(isset($input['v']))	// core edit to fix when $input is empty

Continuing with checking the warnings. I intend all that I find to be documented in this thread.

If you are using a plugin which relies on PluginLibrary, you'll need to upgrade to an updated version.
Thanks to SvePu. https://community.mybb.com/thread-237593...pid1383414

When searching for Today's Posts
Warning [2] Undefined array key "lastread" - Line: 476 - File: search.php PHP 8.0.27 (Linux)
Warning [2] Undefined property: MyLanguage::$pages - Line: 2 - File: search.php(567) : eval()'d code PHP 8.0.27 (Linux)

The first is fixed in line 476 of search.php
Change
				if($thread['lastread'])
to
				if(isset($thread['lastread']))


[edited for correct logic]
				if(isset($thread['lastread']) && $thread['lastread'])


The second is apparently fixed by editing template forumdisplay_thread_multipage from
 <span class="smalltext">({$lang->pages} {$threadpages}{$morelink})</span>
to
 <span class="smalltext">({$threadpages}{$morelink})</span>

or by adding an element to search.lang.php
$l['pages'] = "Pages";

I stuck it in the blank line space at line 10 to maintain consistency with other MultiPage formats.

If you are using the absolutetime plugin by doylecc, which is fantastic already, you'll need to modify it so that it does not generate a warning under PHP 8.0 in ACP / Plugins page. If present, but not active, warning is given for undefined array key 'absolutetime'

Change
    if (absolutetime_is_installed()
        && is_array($plugins_cache)
        && is_array($plugins_cache['active'])
        && $plugins_cache['active']['absolutetime'] // this line errors
    ) {
        if (absolutetime_apply() !== true) {
            $absolutetime_info['description'] .= '<br /><span style="color:red; font-size:1.2em;">'
            .$lang->at_warn_core_edit.'</span>';
        }

to

	if (empty($plugins_cache) || !is_array($plugins_cache)) {
		$plugins_cache = $cache->read('plugins');
	}
	$active_plugins = $plugins_cache['active'];

    if (absolutetime_is_installed()
        && is_array($plugins_cache)
        && is_array($plugins_cache['active'])
        && !empty($active_plugins['absolutetime'])
    ) {
        if (absolutetime_apply() !== true) {
            $absolutetime_info['description'] .= '<br /><span style="color:red; font-size:1.2em;">'
            .$lang->at_warn_core_edit.'</span>';
        }
I have moved the changes over to my production server and changed to PHP 8.0.27, and asked my forum members to identify any additional pages that display warning messages that I have not seen.

If I receive any reports, I will identify them here in this thread.
Several warnings are generated when searching for keyword in posts, with fulltext search, displaying results as posts.

Undefined variable $inquote in lines 363, 381 and 487 in inc/functions_search.php
Using the same same logic as in other functions there, I have added a new line at 358
	$inquote = false;

Warning using array offset on value of type null in eval'd code generated from forum/search.php in line 983
That line evaluates forumdisplay_thread_gotounread template which calls for a value in $thread['newpostlink']
Following similar logic in other functions there, I have added a new line at 983
				$thread['newpostlink'] = get_thread_link($post['thread_lastpost']);

If the logic is incorrect, I'd hope someone with better programming skills would advise such and tell me why.
I'm approaching this endeavor as a learning opportunity.

edit to add:
There was a circumstance when displaying search results which generated a undefined array key 'sid' warning from forum/search.php in line 63.
edited to add explanation and correct fix:
A member used an old search as a bookmarked entry to return to the forum. The sid is expired.
Change line 63 from
	if(!$search['sid'])
to
	if(isset($search['sid']) && !$search['sid'])
This one works better.
	if(empty($search['sid']))
When not mod and visible != 1

Undefined variable $status_type in eval'd code from inc/functions_post.php

Add line 787
$status_type='';
In the process of troubleshooting a plugin, I am told there's a problem with inc/functions.php
I trust the source. Wink

Laird Wrote:line #4591 of inc/functions.php within function get_attachment_icon() needs to be changed from:
    if($attachtypes[$ext]['icon'])
to
    if(!empty($attachtypes[$ext]['icon']))
HLFadmin - what is valid? I will create a PR... thx!
Easier to evaluate current error.log
When a warning occurs, I will start a new thread on each one.

Thank you for monitoring this forum.