代码之家  ›  专栏  ›  技术社区  ›  Xaver

无法重新声明自定义方法

php
  •  0
  • Xaver  · 技术社区  · 8 年前

    我 随机

    Fatal error: Cannot redeclare my_thing() (previously declared in /foo/functions.php:9) in /foo/functions.php on line 21
    

    这是该文件中的函数:

    function my_thing( $subclass = null ) {
        global $my_thing;
    
        $args = func_get_args();
        $subclass = array_shift( $args );
    
        if ( is_null( $subclass ) ) {
            return $my_thing;
        }
    
        return call_user_func_array( array( $my_thing, $subclass ), $args );
    
    }
    

    此块的第一行是中的第9行 functions.php 最后一个括号是第21行。

    那怎么可能呢 my_thing() 两次在线#21

    functions.php文件是 require_once

    旁注 :这是一个包装器方法,因此我可以像 my_thing('subclass')->get_it()

    0 回复  |  直到 8 年前
    推荐文章