Re: overprotective?

From: Date: Wed, 06 Apr 2005 14:23:48 +0000
Subject: Re: overprotective?
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-37114@lists.php.net to get a copy of this message
Lukas Smith wrote:
Robin Ericsson wrote:
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).
Not really sure what you mean here :)
lets say I have class base { private $extended; public function foo() {
    $this->bar();
} private function bar() {
    echo 'bar';
} } and then I refactor the class to load code on demand class base { private $extended; public function foo() {
    $this->bar();
} public function __call($method, $params) {
    call_user_func_array(array(&$this->extended, $method), $params);
} } class extended { // needs to be come public now ... private function bar() {
    echo 'bar';
} }
AFAIK external calls to objects stored in members is not good design, ss your example demonstrates clearly... Also, if a method is marked private, it is to prevent wrappers to access it. Private method should really be used with caution but they are usefull to do the dirty work that could be at risk if an extended class interefered with it. -Philippe

« previous php.pear.dev (#37114) next »