note 44520 added to language.oop5.visibility
| From: | seec77 at zahav dot net dot il | Date: | Sun, 08 Aug 2004 23:54:39 +0000 |
| Subject: | note 44520 added to language.oop5.visibility | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74263@lists.php.net to get a copy of this message | ||
"[...] 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.
----
Manual Page -- http://www.php.net/manual/en/language.oop5.visibility.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44520
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44520&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44520&report=yes
Search -- http://master.php.net/manage/user-notes.php