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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -