MyBB Community Forums

Full Version: inc/functions_search.php warnings 1.8.36
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Errors are generated in inc/functions_search.php on a fulltext search using default search parameters with a unique keyword.
Undefined variable $inquote

<error>
	<dateline>1693907855</dateline>
	<datetime>2023-09-05 09:57:35 UTC -0500</datetime>
	<script>inc/functions_search.php</script>
	<line>363</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined variable $inquote</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/functions_search.php:363]
#2  clean_keywords_ft() called at [/inc/functions_search.php:1468]
#3  perform_search_mysql_ft() called at [/search.php:1599]
</back_trace>
</error>

<error>
	<dateline>1693907855</dateline>
	<datetime>2023-09-05 09:57:35 UTC -0500</datetime>
	<script>inc/functions_search.php</script>
	<line>381</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined variable $inquote</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/functions_search.php:381]
#2  clean_keywords_ft() called at [/inc/functions_search.php:1468]
#3  perform_search_mysql_ft() called at [/search.php:1599]
</back_trace>
</error>

<error>
	<dateline>1693907855</dateline>
	<datetime>2023-09-05 09:57:35 UTC -0500</datetime>
	<script>inc/functions_search.php</script>
	<line>467</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined variable $inquote</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/functions_search.php:467]
#2  clean_keywords_ft() called at [/inc/functions_search.php:1468]
#3  perform_search_mysql_ft() called at [/search.php:1599]
</back_trace>
</error>

perform_search_mysql_ft() is called, and it appears $inquote is a local boolean variable, initialized in line 1479.
clean_keywords_ft() is called at line 1468 but there is no initialization of $inquote in that function.
clean_keywords_ft() is only called from one place.

Elsewhere $inquote is initialized as false, in functions perform_search_sql(), help_document_perform_search_mysql(), privatemessage_perform_search_mysql().

I can clear the warning by initializing $inquote in clean_keywords_ft() before line 358
	$inquote = false; // core edit, added
although it may be better placed elsewhere.
Additionally, when fulltext search is enabled and no search terms are entered, an error is generated.

<error>
	<dateline>1694176122</dateline>
	<datetime>2023-09-08 12:28:42 UTC -0500</datetime>
	<script>inc/functions_search.php</script>
	<line>1530</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined array key "author"</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/functions_search.php:1530]
#2  perform_search_mysql_ft() called at [/search.php:1716]
</back_trace>
</error>

<error>
	<dateline>1694176122</dateline>
	<datetime>2023-09-08 12:28:42 UTC -0500</datetime>
	<script>inc/functions_search.php</script>
	<line>1564</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined array key "postdate"</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/functions_search.php:1564]
#2  perform_search_mysql_ft() called at [/search.php:1716]
</back_trace>
</error>

<error>
	<dateline>1694176122</dateline>
	<datetime>2023-09-08 12:28:42 UTC -0500</datetime>
	<script>inc/functions_search.php</script>
	<line>1582</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined array key "numreplies"</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/functions_search.php:1582]
#2  perform_search_mysql_ft() called at [/search.php:1716]
</back_trace>
</error>

<error>
	<dateline>1694176122</dateline>
	<datetime>2023-09-08 12:28:42 UTC -0500</datetime>
	<script>inc/functions_search.php</script>
	<line>1596</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined array key "threadprefix"</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/functions_search.php:1596]
#2  perform_search_mysql_ft() called at [/search.php:1716]
</back_trace>
</error>

Note, that the line numbers are offset by the code change entered above.

Replace line 1530 with
	if(!empty($search['author'])) // core edit, originally if($search['author'])
Replace line 1564 with
	if(!empty($search['postdate'])) // core edit, originally if($search['postdate'])
Replace line 1582 with
	if(isset($search['numreplies']) && $search['numreplies'] != '' && $search['findthreadst']) // core edit, originally if($search['numreplies'] != '' && $search['findthreadst'])
Replace line 1596 with
	if(!empty($search['threadprefix']) && $search['threadprefix'][0] != 'any') // core edit, originally if($search['threadprefix'] && $search['threadprefix'][0] != 'any')
I have noticed a typo in my post above.
I have edited the variable in line 1564 to reflect the actual code change.