php一个简易 的异步加载类

php一个简易 的异步加载类

func = $func;
        $this->arg = $arg;

    }

    function __get($name) {

        if ($this->data === false) {
            $this->data = call_user_func_array($this->func, $this->arg);

        }

        return $this->data->$name;
    }

}
g2 = $str;
    }
}

class Dev {
    public $d1 = 'this is d1';
    public $d2 = 'this is d2';
    
    function __construct($str) {
        $this->goods = new _async(function($arg){return new Goods($arg);}, [$str]);
    }
}

$dev = new Dev('dev\'s arg to goods');
echo $dev->goods->g1,'
',$dev->goods->g2;

输出 :

结果

你可能感兴趣的:(php一个简易 的异步加载类)