欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

带你穿越带你飞~,一秒钟PHP变JS =^ =!!!

程序员文章站 2022-04-09 10:26:03
...
跳至
class testMet
{
    public function __construct(\Closure $method)
    {
        $bind = \Closure::bind($method, $this);
        $bind();
    }
 
    public function name() 
    {
        var_dump('Oh, My God');
    }
}
 
class papa
{
    public function __construct()
    {
        $that = $this;
        (new testMet(function () use($that)
        {
            // 注意哦,这里的 $this 就不再是papa类的对象咯,而是testMet构造出来的哦~
            $that->_tn('Levi');
            $this->name();
        }));
    }
 
    protected function _tn($name)
    {
        var_dump('I am '.$name);
    }
}
 
class son extends papa
{
    protected function _tn($name)
    {
        var_dump('Her is '.$name);
        parent::_tn('Lucy');
    }
}
 
new son('Levi');