Variable functions with namespaces in PHP

前端 未结 4 2241
孤街浪徒
孤街浪徒 2021-02-14 02:58

I\'m wondering if there is a way to call variable functions with namespaces. Basically I\'m trying to parse tags and send them to template functions so they can render html`

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-14 03:52

    This will also work, no need for call_user_func, just use the Variable functionsDocs feature:

    require_once 'template.php';
    
    $ns = 'template';
    foreach (array('javascript', 'script', 'css') as $tag) {
        $ns_func = $ns . '\\' . $tag;
        echo $ns_func();
    }
    

提交回复
热议问题