阅读背景:

如何在PHP 5中动态调用子类方法?

来源:互联网 
<?php
class foo
{
    //this class is always etended, and has some other methods that do utility work
    //and are never overrided
    public function init()
    {
        //what do to here to call bar->doSomething or baz->doSomething 
        //depending on what class is actually instantiated? 
    }

    function doSomething()
    {
        //intentionaly no functionality here
    }


}

class bar extends foo
{
    function doSomething()
    {
        echo "bar";
    }
}

class baz extends foo
{
    function doSomething()
    {
        echo "baz";
    }
}
?>
<?php
class foo
{
    //this class is always et



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: