我想自动加载函数,而不是类。错误:
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';
}