PHP 7.2 Function create_function() is deprecated Topic is solved

Need help upgrading your Joomla! website or converting to Joomla! 3.x?

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
skamaria
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Jan 11, 2019 10:56 pm

PHP 7.2 Function create_function() is deprecated

Post by skamaria » Fri Jan 11, 2019 11:03 pm

Since updating to PHP 7.2 I have one remaining problem. The create_function is deprecated and I understand a workaround for my issue might be available by using an anonymous function but I don't know enough about PHP to do this.

The code in question is:

Code: Select all

$var = preg_replace_callback('/[_-]+(.)?/i', create_function('$matches', 'return strtoupper($matches[1]);'), $option);
Anyone know how to make this work function rather than create_function?

Thanks

stevec4
Joomla! Intern
Joomla! Intern
Posts: 74
Joined: Mon Jul 29, 2013 11:46 am

Re: PHP 7.2 Function create_function() is deprecated

Post by stevec4 » Fri Jan 11, 2019 11:37 pm

Code: Select all

$var = preg_replace_callback('/[_-]+(.)?/i', function($matches, {return strtoupper($matches[1]);}), $option);
You can try something like this, I have not tested it so it may need some further tweeking

skamaria
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Jan 11, 2019 10:56 pm

Re: PHP 7.2 Function create_function() is deprecated

Post by skamaria » Sat Jan 12, 2019 12:03 am

stevec4 wrote:
Fri Jan 11, 2019 11:37 pm

Code: Select all

$var = preg_replace_callback('/[_-]+(.)?/i', function($matches, {return strtoupper($matches[1]);}), $option);
You can try something like this, I have not tested it so it may need some further tweeking
Thanks for the suggestion but get an error:

syntax error, unexpected '{', expecting variable (T_VARIABLE)

Tried some other variations as well with no success.

Alejo
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 219
Joined: Fri Aug 19, 2005 12:28 pm
Contact:

Re: PHP 7.2 Function create_function() is deprecated

Post by Alejo » Sat Jan 12, 2019 2:43 pm

Try this:

Code: Select all

$var = preg_replace_callback('/[_-]+(.)?/i', function($matches) { return strtoupper($matches[1]); }, $option);
https://www.jreviews.com/joomla directory and reviews system for Joomla and WordPress

skamaria
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Jan 11, 2019 10:56 pm

Re: PHP 7.2 Function create_function() is deprecated

Post by skamaria » Sat Jan 12, 2019 6:22 pm

Alejo wrote:
Sat Jan 12, 2019 2:43 pm
Try this:

Code: Select all

$var = preg_replace_callback('/[_-]+(.)?/i', function($matches) { return strtoupper($matches[1]); }, $option);
This did it! Thank you so much for taking the time to help. It is much appreciated.


Post Reply

Return to “Migrating and Upgrading to Joomla! 3.x”