外部对象 user 
class a{
  public $user;
}怎么把外部对象赋值给 class->user ? 

解决方案 »

  1.   

    创建一个setuser函数进行注入user对象
      

  2.   

    function setUser($user){
     $this->user = user;
    }是这样吗 我试了没反应呀 
      

  3.   

    $user = "aa";
    class Test{
    public $user;

    function __construct(){

    }

    function setUser($user){
    $this->user = $user;
    echo $this->user;
    }
    }
    $test = new Test();
    $test->setUser($user);可以输出aa
      

  4.   


    function setUser($user){
     $this->user = $user; // 你少了$
    }