1

Getting Function create_function() is deprecated Error in laravel 5.4 and php 7.2. Not able to find solution.

please see below code

 public static function delimiterToCamelCase($string, $delimiter = '[\-\_]')
{
    // php doesn't garbage collect functions created by create_function()
    // so use a static variable to avoid adding a new function to memory
    // every time this function is called.
    static $callback = null;
    if ($callback === null) {
        $callback = create_function('$matches', 'return strtoupper($matches[1]);');
    }
    return preg_replace_callback('/' . $delimiter . '(\w)/', $callback, $string);
}

please help.

1 Answer 1

1

create_function has been deprecated as of php 7.2. Instead you can use anonymous_function.

if ($callback === null) {
     $callback = function ($matches) {
         return strtoupper($matches[1]);
     };
}
Sign up to request clarification or add additional context in comments.

2 Comments

do i need to replace your code in delimiterToCamelCase function?
yes, but only If this code is not in the vendor directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.