How can I use PHP closure function like function() use() on PHP 5.2 version?

前端 未结 3 481
一向
一向 2021-01-27 12:48

How can I use PHP closure function like function() use() on PHP 5.2 version as it has no support for anonymous functions?

Currently my code is something like below

3条回答
  •  情深已故
    2021-01-27 13:21

    Something like that should do:

    $this->init(create_function('','
        $taxonomy_name = '.var_export($taxonomy_name,TRUE).'; 
        $plural = '.var_export($plural,TRUE).'; 
        $post_type_name = '.var_export($post_type_name,TRUE).'; 
        $options = '.var_export($options,TRUE).'; 
    
        $options = array_merge(
           array(
              "hierarchical" => false,
              "label" => $taxonomy_name,
              "singular_label" => $plural,
              "show_ui" => true,
              "query_var" => true,
              "rewrite" => array("slug" => strtolower($taxonomy_name))
            ), $options
          );
    
          // name of taxonomy, associated post type, options
          register_taxonomy(strtolower($taxonomy_name), $post_type_name, $options);
    '));
    

提交回复
热议问题