class Test extends thread {
function __construct(&$db,$userObj) {
$this -> userObj = $userObj;
print "Original:";
var_dump($db);
$this->db = $db;
print "InThread:";
var_dump($this->db);
// as value of $this->db and db(in constructor) is different I am gettting different values.
}
public function run(){
$userId = $this->userObj->getUserId();
$data = $this->db->getData();
// as value of $this->db and db(in constructor) is different I am getting different values.
}
function getData(&$db,$userObj){
$thread = new Test($db,$userObj);
$thread->start();
}
我想在我的运行函数中使用 db 的值。如何在不更改 $db 值的情况下通过 run() 访问线程构造函数变量。