PHP 7.2 Function create_function() is deprecated

前端 未结 4 1168
庸人自扰
庸人自扰 2020-11-22 07:18

I have used create_function in my application below.

$callbacks[$delimiter] = create_function(\'$matches\', \"return \'$delimiter\' . strtolower(\\$matches[1         


        
4条回答
  •  有刺的猬
    2020-11-22 07:54

    I would like to contribute with a very simple case I found in a Wordpress Theme and seems to work properly:

    Having the following add_filter statement:

    add_filter( 'option_page_capability_' . ot_options_id(), create_function( '$caps', "return '$caps';" ), 999 );
    

    Replace it for:

    add_filter( 'option_page_capability_' . ot_options_id(), function($caps) {return $caps;},999);
    

    We can see the usage of function(), very typical function creation instead of a deprecated create_function() to create functions. Hope it helps.

提交回复
热议问题