note 59224 added to language.oop5.basic
| From: | npugh at tacc dot utah dot edu | Date: | Tue, 29 Nov 2005 22:10:03 +0000 |
| Subject: | note 59224 added to language.oop5.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99328@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59224
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59224&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59224&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59224&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59224&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59224&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59224&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59224&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59224&report=yes
Search -- http://master.php.net/manage/user-notes.php