PHP class not storing reference -
how pass reference object constructor, , allow object update reference?
class a{ private $data; function __construct(&$d){ $this->data = $d; } function adddata(){ $this->data["extra"]="stuff"; } } // somewhere else $arr = array("seed"=>"data"); $obj = new a($arr); $obj->adddata(); // want $arr contain ["seed"=>"data", "extra"=>"stuff"] // instead contains ["seed"=>"data"]
you must store everywhere reference.
function __construct (&$d) { $this->data = &$d; // & here }
Comments
Post a Comment