在PHP中通过另一个扩展类加载类时遇到问题

I have three class: A, B and C. In class A, A.php:

class A
{
    function __Contruct()
    {
          //do something
    }
}

In class B, B.php:

class B extends A
{
    function __Contruct()
    {
         //do something
    }
}

In class C:

class C
{
    function __Contruct()
    {
         include(A.php);
         $this->A = new A;
         include(B.php);
         $this->B = new B;
    }
    function _load()
    {
         //load class $X;
    }
}

I need to load a class whose name is value of a variable:$X to class without word new in class B.

Can I do it this way:$this->classname->functionname();//classname is value of $X in file B.php.

You extend class B with class A, so why didn't you extend class C with class B? Then you can access all properties & methods of class A and class B.

No need of

$this->classname->functionname();

or you can access method or property as follows,

A::functionname();
B::functionname();
C::functionname();

I think what you want are:

$var = new $X;

to create an instance of class $X and

$X::functionname()

to call a method of class $X.

UPDATE:

If $this->classname returns the name of a class, maybe what you need is:

($this->classname)::functionname();