综合编程

Overwrite the use of the extended class namespace in PHP

微信扫一扫,分享到朋友圈

Overwrite the use of the extended class namespace in PHP
0

Overwrite namespace usage in extended class

Is it possible to overwrite the used namespace of the parent class without rewriting the function in the extended class?

For clarification i write down an example:

i have two classes like this:

namespace one;
class hey
{
    public static function say()
    {
        echo "hey";
    }
}

and

namespace two;
class hey
{
    public static function say()
    {
        echo "ho";
    }
}

Now i use on of the namespaces in this class:

use onehey;
class saysomething
{
    public static function main()
    {
        hey::say();
    }
}

Now i want to extend the last class:

class extended extends saysomething
{
}

extended::main();

In this class i want to use namespace “twoone” without overwriting the function, is it possible? *f it is, how? Thank you for your time.

You can add use
statement when declaring class extended
like this:

use oneheysaysomething;
class extended extends saysomething
{
}

extended::main();

Or you can extend the class using full namespace like this:

class extended extends oneheysaysomething {

}

extended::main();

阅读原文...


Hello, buddy!

Carpooling service Klaxit partners with Uber for last-minute changes

上一篇

LINQ Lambda Summing NULL

下一篇

您也可能喜欢

评论已经被关闭。

插入图片
Overwrite the use of the extended class namespace in PHP

长按储存图像,分享给朋友