如何从非实例化的类调用该对象

ilh*_*ctn 2 php overloading object

关于重载的手册,我无法掌握其中一个线程.代码如下:

<?php

class a
{
   function __get($v)
   {
       $this->$v = new $v;
       return $this->$v;
   }
}

class b
{
    function say($word){
        echo $word;
    }
}
$a = new a();
$a->b->say('hello world');

// echos 'hello world'
?> 
Run Code Online (Sandbox Code Playgroud)

正如在评论中指出的那样,它与你的世界相呼应.但即使b尚未实例化,它是如何被调用的?请帮忙,链接到手册在这里,条目属于gmail dot com中名为trash80的用户

Nea*_*eal 6

它能做什么:

$a->b:

function __get('b'){
    $this->b = new b;
    return $this->b;
}
Run Code Online (Sandbox Code Playgroud)

$a->b->say('hello world'):

function say('hello world'){
    echo 'hello world';
}
Run Code Online (Sandbox Code Playgroud)