0

クラスではなく、関数を自動ロードしたいと思います。エラー:

PHP 致命的なエラー: 7 行目の /var/www/localhost/proba-function.php で proba() (以前に /var/www/localhost/proba-function.php:5 で宣言) を再宣言できません

index.php コード:

class ASD {
    function __construct () {
        self::proba();
    }

    public static function __callStatic ( $name, $arguments ) {
        $foo = false;
        $directories = array_diff ( scandir ( __DIR__ ), array ( '..' ) );

        foreach ( $directories as $directory ) {
            $directory = __DIR__ . DIRECTORY_SEPARATOR . $directory;
            if ( is_dir ( $directory ) ) {
                $file = $directory . DIRECTORY_SEPARATOR . strtolower ( $name ) . '-function.php';
                if ( file_exists ( $file ) ) {
                    include ( $file ); // It's ok.
                    if ( function_exists ( $name ) ) {
                        $foo = true;
                        call_user_func_array(array('ASD', $name), $arguments); // It's not work.
                        break;
                    } else {}
                } else {}
            } else {}
        }

        if ( $foo === FALSE ) {
            $this -> error ( NULL, $name );
        } else {}
    }
}

proba-function.php:

function proba () {
    print 'foo';
}
4

1 に答える 1

6

同じファイルが複数回含まれないように、include()呼び出しをに置き換えてみてください。include_once()

ファイルが実際に含まれていることを確認するrequire_once()には、単純なinclude_once().

ドキュメントも参照してください: http://php.net/manual/en/function.include.php

于 2012-09-24T08:47:27.473 に答える