PHP Tutorial – 12 – Access Levels
The access level of a class member can be defined by prefixing the declaration with either public, protected, or private. Public is the default access level for all class members.
class MyClass { public $myPublic; // unrestricted access protected $myProtected; // defining or derived class private $myPrivate; // defining class only }
Private access
All members regardless of their visibility are available in the class where they are defined. This is the only place where the private member can be accessed.
class MyClass { function test() { $myPublic = 0; // allowed $myPrivate = 0; // allowed $myProtected = 0; // allowed } }
Protected access
A protected member can be accessed from inside of a derived class as well as from within the defining class.
class MyChild extends MyClass { function test() { $myPublic = 0; // allowed $myProtected = 0; // allowed $myPrivate = 0; // inaccessible } }
Public access
Public members have unrestricted access, which means that they can be reached even from outside of the class from instances of the class.
$m = new MyClass(); $m->myPublic = 0; // allowed $m->myProtected = 0; // inaccessible $m->myPrivate = 0; // inaccessible
If you like this tutorial please +1 it:


![[Affiliate link] Total Training]( http://d3qzmfcxsyv953.cloudfront.net/images/pvt-affiliates/totaltraining.png)
![[Affiliate link] Lynda](http://d3qzmfcxsyv953.cloudfront.net/images/pvt-affiliates/lynda.png)


@admin… Hope the DVD, would be more comprehensive than the text version.. Keep the flag flying…
Great Job….
That is in the works. Hopefully, there will be DVD versions of the tutorials available before the end of 2011. Cheers.
where can i get dvd of alll these tutorial ?.
good tutorial