It seems today is a day for coding standards ;)

At the moment, I do not have a justification for making these __get()/__set()/__isset()/__unset() magic methods public. However, I can think of several reasons they should not be public, as nicely presented by Ralph.

Can anyone think of a reasonable use case for why these methods need to be public? Even if we find some use case, perhaps we could still strongly suggest these methods be protected, unless the author has a very good reason for making them public.

Thoughts anyone?

Cheers,
Gavin

Simon Mundy wrote:
Hi Ralph

I was about to ask the same thing, but your explanation makes complete sense.

Should we take this as another unofficial coding standard that these magic methods should all be protected (except __construct, of course, for where it needs to be public)?

The reason it was made protected was to prevent the masses from using the __get()/__set()/__isset()/__unset() methods directly, as that usage is frowned upon.. ie: $session->__get($name);

The reason is to protect from unintentional misuse.  As this scenario:

$session = new Zend_Session();
$var = array('foo'=>'bar');
$session->__set($var, 'value');

Would produce unexpected results.

-ralph

Reply via email to