php - namespace和use的使用问题(已附上详细例子)
巴扎黑
巴扎黑 2017-04-11 10:14:24
0
2
307

同级目录下有两个php文件

问题:
我如何在indexb.php中的class c中分别调用index.php中class a 和 class b的静态方法?
namespace 和 use 该怎么填?
文件一:index.php

namespace { use class a{ static public function speak($a) { echo $a; } } } namespace { use class a{ static public function speak($a) { echo $a.$a; } } }

文件二:indexb.php

namespace Php { class c { } }
巴扎黑
巴扎黑

全員に返信 (2)
PHPzhong

文件index.php:

文件indexb.php

运行indexb.php 结果I am A!I am B!

いいねを押す+0
    阿神

    是不是你想要的结果?

    index.php

    indexb.php

    a); a::speak($this->a); // \test2\b::speak($this->a); b::speak($this->a); } } $c = new \testt\c(); $c->a = 'zhansan'; $c->speak(); }
    いいねを押す+0
      最新のダウンロード
      詳細>
      ウェブエフェクト
      公式サイト
      サイト素材
      フロントエンドテンプレート
      私たちについて 免責事項 Sitemap
      PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!