namespace and use issues (detailed examples are attached)

Source: Internet
Author: User
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 ();}   
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.