PHP 8 issues - Deprecated: preg_match()

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 22, 2022   (RSS)

By Deborah - June 17, 2022


With CMSB 3.56, when clicking 'Save Details' button in admin of a single-record section editor, the error below appears.
• Does not happen with multi-record section editors.
• Happens with PHP 8.1.5 or 8.1.6, but NOT with PHP 8.0.20 or PHP 7.4.29.

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/myweb/public_html/cms/lib/menus/database/editTable_functions.php on line 250 Warning: Cannot modify header information - headers already sent by (output started at /home/myweb/public_html/cms/lib/menus/database/editTable_functions.php:250) in /home/myweb/public_html/cms/lib/menus/header.php on line 4

editTable_functions.php line 250:

$startsWithHttpOrSlash = preg_match("|^(\w+:/)?/|", @$_REQUEST[$name]);

Error looks similar to this post:

I'm not clear on what to edit to compensate for PHP's changes.


By daniel - June 21, 2022

Thanks for the report Deborah!

This should be fixed for the next CMSB version, but in the meantime, it can be patched by replacing line 250 with this:

$startsWithHttpOrSlash = preg_match("|^(\w+:/)?/|", $_REQUEST[$name]??'');

Also, just to arm you in case you run across similar unpatched PHP 8.1 deprecation warnings (specifically ones that mention "passing null"), note which function and parameter is throwing the warning (in this case, preg_match() and parameter #2), and add ??'' to the end of the variable being passed to that parameter. It's also possible to remove the @ from the variable if there is one. So this:


became this:


This isn't a fix for 100% of cases, but something worth trying to get the warning cleared up ASAP. Though we always appreciate reports like this regardless!


Technical Lead

By Deborah - June 22, 2022 - edited: June 22, 2022


Your fix worked!

I'll take note of your suggestion if I should see that type of warning again.

Thanks so much!