Re: overprotective?
| From: | Lukas Smith | Date: | Wed, 06 Apr 2005 11:13:54 +0000 |
| Subject: | Re: overprotective? | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-37109@lists.php.net to get a copy of this message | ||
Robin Ericsson wrote:
Lukas Smith wrote:Protected properties cannot be modified from the outside either. Aside from that its not really efficient to force everything through setters/getters in PHP, so I dont think we should proclaim this as evil so easily. Aside from this there is one serious drawback to labeling things with private/protected. When using __call() to dynamically add functionality through objects that are created ondemand and stored as properties you quickly run into problems. There visibility "package" would probably be wiser to use, even if its not supported in PHP5 (and therefore can only be noted via an @access phpdoc comment). regards, LukasHi,Hi!While playing around a bit with php5 visibility I noticed that in PEAR we mostly mark things either private or public. However I think people (including me) just got into the habit of doing so without good reason. Marking things private implies that classes that inherite from the class do not see any of the private properties/methods of their parent. This however is rarely the intention.Making properties protected or public is dangerous. With methods you have some control of what happens, but properties should never be touched outside the class without going through setters/getters (unless you know for a fact that people _will_ get/set them without the class knowing it and therefor can take the actions required)