note 75426 added to language.oop5.visibility
| From: | JoshuaWatt at osu1 dot php dot net | Date: | Tue, 29 May 2007 19:09:08 +0000 |
| Subject: | note 75426 added to language.oop5.visibility | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127000@lists.php.net to get a copy of this message | ||
I couldn't find this documented anywhere, but you can access protected and private member
varaibles in different instance of the same class, just as you would expect
i.e.
<?php
class A
{
protected $prot;
private $priv;
public function __construct($a, $b)
{
$this->prot = $a;
$this->priv = $b;
}
public function print_other(A $other)
{
echo $other->prot;
echo $other->priv;
}
}
class B extends A
{
}
$a = new A("a_protected", "a_private");
$other_a = new A("other_a_protected", "other_a_private");
$b = new B("b_protected", "ba_private");
$other_a->print_other($a); //echoes a_protected and a_private
$other_a->print_other($b); //echoes b_protected and ba_private
$b->print_other($a); //echoes a_protected and a_private
?>
----
Server IP: 69.39.81.135
Probable Submitter: 129.186.111.4
----
Manual Page -- http://www.php.net/manual/en/language.oop5.visibility.php
Edit -- https://master.php.net/note/edit/75426
Del: integrated -- https://master.php.net/note/delete/75426/integrated
Del: useless -- https://master.php.net/note/delete/75426/useless
Del: bad code -- https://master.php.net/note/delete/75426/bad+code
Del: spam -- https://master.php.net/note/delete/75426/spam
Del: non-english -- https://master.php.net/note/delete/75426/non-english
Del: in docs -- https://master.php.net/note/delete/75426/in+docs
Del: other reasons-- https://master.php.net/note/delete/75426
Reject -- https://master.php.net/note/reject/75426
Search -- https://master.php.net/manage/user-notes.php