PHP 7.2 Error

Resolve a deprecated create_function error in ChronoForms after a PHP 7.2 update.

Overview

The error occurs because the deprecated create_function() is used in the CF code, which is no longer supported in PHP 7.2+.
Edit the chronoform.php file at line 410 and replace the deprecated create_function() call with an anonymous function syntax, ensuring to remove the quotes around the parameter.

Answered
jw jwill 10 Oct, 2019
I have several long complex forms on a site that almost never has changes. Because the forms work, I have never wanted to spend the time to rebuild all of the forms. After updating to PHP 7.2, I am receiving the following warning:
​
"Deprecated: Function create_function() is deprecated in /home/metro103/public_html/components/com_chronoforms/libraries/chronoform.php on line 410"
​
Is there an easy fix for this that will keep me from having to rebuild all of the forms?
​
Jim
jw jwill 10 Oct, 2019
Answer
So would the bold part of this line

function _camilize($class = ''){
return preg_replace_callback('/(?:^|_)(.?)/i',create_function('$matches', 'return strtoupper($matches[1]);'), $class);
}
Be changed to this
function('$matches'){return strtoupper ($matches[1];},
Jim
he healyhatman 11 Oct, 2019
function('$matches'){return strtoupper ($matches[1]);},
​
but yes, something like that.
dt dtsilog 04 Aug, 2020
1 Likes
Thank you Bob and all, i had the same error in my Joomla site:
​
"Deprecated: Function create_function() is deprecated in *****/components/com_chronoforms/libraries/chronoform.php on line 410".
​
In chronoform.php file and line 410 i replaced ONLY below code:
create_function('$matches', 'return strtoupper($matches[1]);')
with this:
function($matches){return strtoupper($matches[1]);}
and it worked, error message dissapeard!! The only difference is that function('$matches') needs to be function($matches) - without ' '.
​
Tested on PHP 7.2 and 7.3, i still use Chronoforms 4.0.8 and latest joomla 3.9.20.
​
Thank you again!
This topic is locked and no more replies can be posted.