nicholasstephan Posted February 14, 2009 Share Posted February 14, 2009 Hey, I'm overriding the __get and __set methods, but there are a few situations where I'd still like to have access to some local variables without having to go through them. For example: overriding the __set method, I have all variables stored in a $data array. So $myClass->someVariable = "someValue", stores $data['someVariable'] => "someValue". But I also have a protected var for $username and $password. Is there a way of accessing these without going through my getter and setter. I don't really want to have to make special case ifs for every internal variable in my getter and setter. Thanks, Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 14, 2009 Share Posted February 14, 2009 __get() and __set() are only used for inaccessible members, so if you try to access $this->privateMember, it WON'T go through the __get() method unless you're doing it outside of the object. If you DO want to access it outside of the object, you shouldn't be accessing it directly in the first place, use a getter method... <?php class Whatever { private $variable; //... public function getVariable() { return $this->variable; } //... } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.