note 60382 added to language.oop5.visibility
| From: | r dot wilczek at web-appz dot de | Date: | Thu, 05 Jan 2006 13:11:33 +0000 |
| Subject: | note 60382 added to language.oop5.visibility | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101248@lists.php.net to get a copy of this message | ||
Beware: Visibility works on a per-class-base and does not prevent instances of the same class
accessing each others properties!
<?php
class Foo
{
private $bar;
public function debugBar(Foo $object)
{
// this does NOT violate visibility although $bar is private
echo $object->bar, "\n";
}
public function setBar($value)
{
// Neccessary method, for $bar is invisible outside the class
$this->bar = $value;
}
public function setForeignBar(Foo $object, $value)
{
// this does NOT violate visibility!
$object->bar = $value;
}
}
$a = new Foo();
$b = new Foo();
$a->setBar(1);
$b->setBar(2);
$a->debugBar($b); // 2
$b->debugBar($a); // 1
$a->setForeignBar($b, 3);
$b->setForeignBar($a, 4);
$a->debugBar($b); // 3
$b->debugBar($a); // 4
?>
----
Manual Page -- http://www.php.net/manual/en/language.oop5.visibility.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60382
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60382&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60382&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60382&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60382&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60382&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60382&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60382&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60382&report=yes
Search -- http://master.php.net/manage/user-notes.php