Amin Amin - 6 months ago 10
PHP Question

How to send and extract class

I need to send and get Class into another class like a variable in MVC method :

class Demo {

private $vars = array();

function set($var , $data) {
$this->vars[$var] = $data;
}


function request() {

extract($this->vars);

var_dump($vars);

}

}


And i want to use above class into this :

class Test extends foo {

function __construct(){
$this->demo = new Demo();
}

function register(){
$user = Load::model('user');//Now User Is An Object
$this->demo->set('user',"$user");//This Is Error
$this->demo->request();
}



Catchable fatal error: Object of class user could not be converted to string in

Answer

remove the quotes

$this->demo->set('user', $user);

And don't forget to create your variable in your class scope

class Test extends foo {
    public $demo;

should do the trick