The visibility of a property or method can be defined by prefixing the
declaration with the keywords: public, protected or private. Public
declared items can be accessed everywhere. Protected limits access to
inherited and parent classes (and to the class that defines the item).
Private limits visibility only to the class that defines the item.
$obj2 = new MyClass2(); echo $obj->public; // Works echo $obj2->private; // Undefined echo $obj2->protected; // Fatal Error $obj2->printHello(); // Shows Public, Protected2, not Private
The PHP 4 method of declaring a variable with the
var keyword is no longer valid
for PHP 5 objects. For compatibility a variable declared
in php will be assumed with public visibility, and a
E_STRICT warning will be issued.