Home  >  Article  >  php教程  >  带你穿越带你飞~,一秒钟PHP变JS =^ =!!!

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

PHP中文网
PHP中文网Original
2016-05-26 08:21:151099browse

跳至

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');

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn