Not Solved [Error Message] Undefined variable $search_thread
#1
Not Solved
Greetings,
I'm running myBB-1.8.32 on a Linux server.  Everything works fine when using php-7.4.33.  However, as soon as I update to php-8.0.x (or 8.1.x) every page load of the myBB forum triggers the following error message:
Type: 2
File: showthread.php(1617) : eval()'d code (Line no. 60)
Message
Undefined variable $search_thread
Back Trace: #0 /var/www/html/dv/inc/class_error.php(229): errorHandler->email_error(2, 'Undefined varia...', 'showthread.php(...', 60)
#1 /var/www/html/dv/inc/class_error.php(153): errorHandler->error(2, 'Undefined varia...', 'showthread.php(...', 60)
#2 /var/www/html/dv/showthread.php(1617) : eval()'d code(60): errorHandler->error_callback(2, 'Undefined varia...', '/var/www/html/d...', 60)
#3 /var/www/html/dv/showthread.php(1617): eval()


As php-7.x has become EOL, I really need to update to an 8.x version soon to ensure timely security updates.  Is the above a known issue?  Is there any workaround for php-8.x?

thanks!
Reply
#2
Not Solved
$search_thread is defined in line 803 of showthread.php
If usergroup 'cansearch' is true, the $search_thread variable is populated with showthread_search template.
showthread template calls that variable at the end of the posts container.

I'm still running 1.8.30 using php 7.4, so I can't do more than look at the framework of its use.
This is an excellent resource for cross-referencing, always updated to show only the current version.
https://crossreference.mybb.de/nav.html?...index.html

The first place to look is if there is a problem with the showthread_search template.
You don't say whether the errors occur on default theme or custom theme.

I will look if you provide a URL.
Reply
#3
Not Solved
Sorry for the delayed reply.

@HFLadmin

I'm seeing this problem with the default theme.

Not sure what you mean by "provide a URL". Do you mean the URL of my myBB instance ?
Reply
#4
Not Solved
Make sure your templates have been reverted to default, you can find outdated templates at ACP > Templates & Style > Templates > Find Updated Templates.
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#5
Not Solved
(2022-12-14, 02:24 AM)Matt Wrote: Make sure your templates have been reverted to default, you can find outdated templates at ACP > Templates & Style > Templates > Find Updated Templates.

When I go there, I see:

There are currently no templates which have been updated since you last upgraded.
Reply
#6
Not Solved
1. Look to see if showthread.php is not altered.
AdminCP / Tools and Maintenance / File Verification

2. Check if modifications to showthread template.
AdminCP / Templates & Style / Templates / Default Templates / expand Showthread Templates
Click Options button and view Diff Report of showthread. Any text in template highlighted in color?

3. Verify this segment exists in the showthread template.
<tr>
 <td class="tfoot">
 {$search_thread}
 <div>
 <strong>&laquo; <a href="{$next_oldest_link}">{$lang->next_oldest}</a> | <a href="{$next_newest_link}">{$lang->next_newest}</a> &raquo;</strong>
 </div>
 </td>
 </tr>

4. View Diff Report on showthread_search template in that same group. Any modifications?
It should look like this.
<div class="float_right">
 <form action="search.php" method="post">
 <input type="hidden" name="action" value="thread" />
 <input type="hidden" name="tid" value="{$thread['tid']}" />
 <input type="text" name="keywords" value="{$lang->enter_keywords}" onfocus="if(this.value == '{$lang->enter_keywords}') { this.value = ''; }" onblur="if(this.value=='') { this.value='{$lang->enter_keywords}'; }" class="textbox" size="25" />
 <input type="submit" class="button" value="{$lang->search_thread}" />
 </form>
 </div>

If you provide a link to your forum, I will take a look.
Reply
#7
Not Solved
Oh actually looking at it, the variable may be undefined if searching is not allowed - have you set the permissions so that the forum can't be searched?
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#8
Not Solved
There is only one place $search_thread is defined, in showthread.php

800      // Can this user perform searches? If so, we can show them the "Search thread" form
 801      if($forumpermissions['cansearch'] != 0)
 802      {
 803          eval("\$search_thread = \"".$templates->get("showthread_search")."\";");
 804      }
 805  

In the event cansearch is 0, is PHP8 calling $search_thread as undefined rather than assuming a null value?
Can test by adding a line to define it as null before performing test. Adding

$search_thread = "";

before the if statement may solve. The fix may be a core edit.
Reply
#9
Not Solved
(2022-12-14, 12:37 PM)HLFadmin Wrote: 1. Look to see if showthread.php is not altered.
AdminCP / Tools and Maintenance / File Verification

Only admin/backups/.htaccess is listed with Status = Changed (which is expected).

(2022-12-14, 12:37 PM)HLFadmin Wrote: 2. Check if modifications to showthread template.
AdminCP / Templates & Style / Templates / Default Templates / expand Showthread Templates
Click Options button and view Diff Report of showthread. Any text in template highlighted in color?

The only option under the Options button is "Full Edit".

(2022-12-14, 12:37 PM)HLFadmin Wrote: 3. Verify this segment exists in the showthread template.
<tr>
 <td class="tfoot">
 {$search_thread}
 <div>
 <strong>&laquo; <a href="{$next_oldest_link}">{$lang->next_oldest}</a> | <a href="{$next_newest_link}">{$lang->next_newest}</a> &raquo;</strong>
 </div>
 </td>
 </tr>

It exists, and matches what you provided as lines 57-64.

(2022-12-14, 12:37 PM)HLFadmin Wrote: 4. View Diff Report on showthread_search template in that same group. Any modifications?
It should look like this.
<div class="float_right">
 <form action="search.php" method="post">
 <input type="hidden" name="action" value="thread" />
 <input type="hidden" name="tid" value="{$thread['tid']}" />
 <input type="text" name="keywords" value="{$lang->enter_keywords}" onfocus="if(this.value == '{$lang->enter_keywords}') { this.value = ''; }" onblur="if(this.value=='') { this.value='{$lang->enter_keywords}'; }" class="textbox" size="25" />
 <input type="submit" class="button" value="{$lang->search_thread}" />
 </form>
 </div>

Looks identical to what you provided on my installation.


(2022-12-14, 12:37 PM)HLFadmin Wrote: If you provide a link to your forum, I will take a look.

Sure thing, please see https://dv.netllama.us/dv/ .

(2022-12-14, 01:18 PM)Matt Wrote: Oh actually looking at it, the variable may be undefined if searching is not allowed - have you set the permissions so that the forum can't be searched?

No, searching works fine on my forum, even for unauthenticated users.

(2022-12-14, 04:20 PM)HLFadmin Wrote: There is only one place $search_thread is defined, in showthread.php

800      // Can this user perform searches? If so, we can show them the "Search thread" form
 801      if($forumpermissions['cansearch'] != 0)
 802      {
 803          eval("\$search_thread = \"".$templates->get("showthread_search")."\";");
 804      }
 805  

In the event cansearch is 0, is PHP8 calling $search_thread as undefined rather than assuming a null value?
Can test by adding a line to define it as null before performing test. Adding

$search_thread = "";

before the if statement may solve. The fix may be a core edit.

Adding that initialization of $search_thread before line 801 appears to fix this bug. Thank you!

What's the process for getting this fix into the official myBB code base in a future release?

I spoke too soon.  The original failure is gone, but now I'm getting two new failures, also inside of showthread.php:

Type: 2
File: showthread.php (Line no. 256)
Message
Undefined variable $cutoff
Back Trace: 
#0  errorHandler->email_error(2, Undefined variable $cutoff, showthread.php, 256) called at [/var/www/html/dv/inc/class_error.php:229]
#1  errorHandler->error(2, Undefined variable $cutoff, showthread.php, 256) called at [/var/www/html/dv/inc/class_error.php:153]
#2  errorHandler->error_callback(2, Undefined variable $cutoff, /var/www/html/dv/showthread.php, 256) called at [/var/www/html/dv/showthread.php:256]

Type: 2
File: showthread.php (Line no. 243)
Message
Undefined variable $lastread
Back Trace: 
#0  errorHandler->email_error(2, Undefined variable $lastread, showthread.php, 243) called at [/var/www/html/dv/inc/class_error.php:229]
#1  errorHandler->error(2, Undefined variable $lastread, showthread.php, 243) called at [/var/www/html/dv/inc/class_error.php:153]
#2  errorHandler->error_callback(2, Undefined variable $lastread, /var/www/html/dv/showthread.php, 243) called at [/var/www/html/dv/showthread.php:243]

I guess I need to initialize more variables somewhere to fix this too? 
Is there an easier way to find all the uninitialized variables at once?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)