Magic method __set won't be called for protected variables

From: Date: Tue, 19 Sep 2006 19:10:50 +0000
Subject: Magic method __set won't be called for protected variables
Groups: php.general 
Request: Send a blank email to php-general+get-241952@lists.php.net to get a copy of this message
I have a series of properties set as protected in my class which I meant to have them accessed externally through __set and __get. Unfortunately, it seems that since the properties do exist, the magic methods don't get called, but then I get an error "Cannot access protected property xxxxx", which I didn't meant to access directly, that's what I put the __set and __get magic methods there. There is no problem if the variable has another name than the external property, if I use $obj->something and the variable is declared protected $_something, the magic methods are called, but then I have different 'external' names than the 'internal' ones, something which I wanted to avoid. Since I want to have them with the same name, I might declare the variables public, but I wanted to use the magic methods to validate the values assigned to these variables. Any ideas? Thanks Satyam

« previous php.general (#241952) next »