note 59224 deleted from language.oop5.basic by colder

From: Date: Sun, 19 Aug 2007 23:41:20 +0000
Subject: note 59224 deleted from language.oop5.basic by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129612@lists.php.net to get a copy of this message
Note Submitter: npugh at tacc dot utah dot edu ---- Note that a function defined in the parent class may not access a private member of a child class. <?php class A { public function foo() { echo $this->x; } } class B extends A { protected $x = "class B's member"; } class C extends A { private $x = "class C's member"; } $b = new B(); $b->foo(); $c = new C(); $c->foo(); // Output: // class B's member // Fatal error: Cannot access private property C::$x ?> In the above example, if you don't want to duplicate function foo() in all of the child classes you would have to make each member foo() operates on protected or public. Effectively breaking encapsulation to in order to implement polymorphism.

« previous php.notes (#129612) next »