note 44520 rejected from language.oop5.visibility by tomsommer
| From: | tomsommer@php.net | Date: | Sun, 08 Aug 2004 23:59:25 +0000 |
| Subject: | note 44520 rejected from language.oop5.visibility by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74264@lists.php.net to get a copy of this message | ||
Note Submitter: seec77@zahav.net.il
----
"[...] Public declared items can be allow access to any caller. Protected limits access access
to only classes inherited. Protected limits visiblity only to the class that defines the item."
There is a mistake in this paragraph.
I believe that in the last sentence ("Protected limits visiblity only to the class that defines
the item."), the "Protected" should be replaced by "Private" (or
"Privatized").
It makes sense, that private items are only visible in the class that defined them.
Another proof of this is the example code:
<?php
class MyClass {
public $public = "MyClass::public!\n";
protected $protected = "MyClass::Protected!\n";
protected $protected2 = "MyClass::Protected2!\n";
private $private = "MyClass::private!\n";
//[...]
}
class MyClass2 extends MyClass {
//[...]
}
//[...]
$obj2 = new MyClass2();
print "Main:: " . $obj2->private; /* Undefined */
//[...]
?>
That shows, that the MyClass2's "private" element is undefined, because that
variable is visible only to the class that created it, MyClass, although MyClass2 inherits MyClass.