php oo refrence class member

class Foo{
   private &$member;
   function __construct(&$member){ $this->member = &$member; }
   function doSmtg(){//changes member }
   function doSmtgElse(){//changes member }
}
$myMember = "";
foo = new Foo($myMember);
foo->doSmtg();
echo $myMember;

I am still pretty nez to php, so please bare with me…

I would like to pass $mymember to the constructor of Foo as a ref, so that the changes to it will directly be changed on the $myMember variable aswell.

My code is currently wrong, i get error about unexpected ‘&’ at private &$member;
So i guess something is wrong with my syntax on refrence usage ?

I tried to follow: http://php.net/manual/en/language.references.pass.php

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s