3

例:

namespace Somenamespace;    
use Somenamespace\Someclass;
use Somenamespace\otherclass;


class Template{

  public function display($templ){
    load_template($templ);
  }

}


function load_template($file){
  unset($file);
  require func_get_arg(0);
}

$template = new Template();
$template->display('file.php');

ここで、「use」ステートメントで最初に宣言することなく、file.php の「Someclass」にアクセスしたいと考えています。例えば。someclass::dostuff();(名前空間なし)

出来ますか?

4

1 に答える 1

5

簡単に:いいえ。例の下にある注を参照してくださいhttp://www.php.net/manual/en/language.namespaces.importing.php#example-247

インポート ルールはファイル単位です。つまり、含まれるファイルは親ファイルのインポート ルールを継承しません。

于 2012-10-27T15:47:43.180 に答える