Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import static function with namespace in php?

class A declared at namespace1.

namesapce namesapce1;
class A
{
  public static function fun1()
  {
  }

}

I want to use fun1() inside class B:

namespace namesapce2;
use ???? as fun1
class B
{
    public static func2()
    {
          fun1();
    }
}

How to do that ?

like image 754
david Avatar asked Nov 02 '14 13:11

david


1 Answers

namespace namespace2;

use namespace1\A;

class B
{
    public static function func2()
    {
          A::fun1();
    }
}

Assuming you're using something that does autoloading or the necessary includes.

like image 189
ChadSikorra Avatar answered Oct 25 '22 07:10

ChadSikorra