Two PHP files in a sibling directory
Problem:
How do I invoke the static methods of Class A and Class B in index.php, respectively, in Class C in indexb.php?
How do I fill out the namespace and use?
File One: 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; } }}
File Two: indexb.php
namespace Php { class c { }}
Reply content:
Two PHP files in a sibling directory
Problem:
How do I invoke the static methods of Class A and Class B in index.php, respectively, in Class C in indexb.php?
How do I fill out the namespace and use?
File One: 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; } }}
File Two: indexb.php
namespace Php { class c { }}
File index.php:
文件indexb.php
运行indexb.php 结果I am A!I am B!
Are you looking for results?
index.php
!--? phpnamespace test{class a{static public funct Ion speak ($a) {echo $a; }}}namespace Test2{class B {static public function speak ($a) {echo $a. $a; }}}
indexb.php
"!--? Phpnamespace testt{include ' index.php '; use test\a;use test2\b;class c{public $a; Public Function speak () {//Var_dump (new A);//\test\a::speak ($this--->a); A::speak ($this->a);//\test2\b::speak ($this->a); B::speak ($this->a); }} $c = new \testt\c (); $c->a = ' Zhansan '; $c->speak ();}