php strpos(): Deprecated. error_log is huge -> FIX for content plugin

Resolve PHP 8.2 deprecated strpos() error in ChronoForms content plugin.

Overview

The error occurs because the plugin's code passes a potentially null or non-string value to the strpos() function, which is deprecated in PHP 8.2.
Update the plugin file by adding checks to ensure the article text variable is set and is a string before using strpos() and preg_match_all().

Answered
ChronoForms v8
ze zest96 05 Nov, 2024

chronoforms Version 8.0.23

PHP 8.2

I got this error which filled a nice 1gb error log over few months.

PHP Deprecated:  strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /public_html/plugins/content/chronoforms8/chronoforms8.php on line 22

here is the fix to the core file listed here above ⇧ and one more error coming right after, due to lack of checks of article text and in cases of loading the form in using the plugin {chronoforms 8}formName{/chronoforms8}

search these lines:

        // Simple performance check to determine whether bot should process further
        if (strpos($article->text, '{chronoforms8}') === false) {
            return;
        }
		
		preg_match_all('#{chronoforms8}(.*?){/chronoforms8}#s', $article->text, $matches);
		

replace with this

 // Simple performance check to determine whether bot should process further
// php 8.2 deprecated fixes

if (isset($article->text) && is_string($article->text) && strpos($article->text, '{chronoforms8}') === false) {
    return;
}
		
if (!empty($article->text) && is_string($article->text)) {
    preg_match_all('#{chronoforms8}(.*?){/chronoforms8}#s', $article->text, $matches);
}

Max_admin Max_admin 06 Nov, 2024
Answer
1 Likes

Thank you for the fix, I have updated the download!

You can replace the first check with:

// Simple performance check to determine whether bot should process further
		if(empty($article->text)){
			return;
		}
		if (strpos($article->text, '{chronoforms8}') === false) {
			return;
		}
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.