6

标题中提到的可能吗?Python 模块样式就是这样。请参阅此示例以了解我的确切含义。

索引.php

<?php
use Hello\World;
World::greet();

你好/World.php

<?php
namespace Hello\World;
function greet() { echo 'Hello, World!'; }

这可能吗?

4

1 回答 1

5

是的,看看spl_autoload_register的例子

namespace Foobar;

class Foo {
    static public function test($name) {
        print '[['. $name .']]';
    }
}

spl_autoload_register(__NAMESPACE__ .'\Foo::test'); // As of PHP 5.3.0

new InexistentClass;

上面的示例将输出类似于:

[[Foobar\InexistentClass]]
Fatal error: Class 'Foobar\InexistentClass' not found in ...

这是Autoloader builder的链接,即

是一个命令行应用程序,用于自动生成自动加载包含文件的过程。

于 2010-03-26T11:32:55.307 回答