Symfony 1.4 using deprecated functions in php 5.5

前端 未结 7 918
野趣味
野趣味 2020-12-25 14:48

I recently upgraded PHP from version 5.3.27 to 5.5.0. Everything is working fine in my Symfony 2.3.2 project, and I can enjoy the latest PHP functionalities.

Now wh

7条回答
  •  忘掉有多难
    2020-12-25 15:08

    Basically what you have to do is take the replacement argument from the preg_replace call and factor it out into a proper PHP expression, then make that expression the body of a function that will be used as the callback to the equivalent preg_replace_callback call.

    In your case the relevant code is

    return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", /* input */)
    

    So you would do that as

    $callback = function($matches) {
        return '-'.strtoupper($matches[1]);
    };
    
    return preg_replace_callback('/\-(.)/', $callback, /* input */)
    

    As you can see the callback code is the same as the original replace expression, the only difference being that references such as \\1 are replaced with array accesses like $matches[1].

提交回复
热议问题