1
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的值。如何通過run()訪問線程構造函數變量而不更改$ db值。如何在運行函數中訪問線程構造函數的變量?