object PHP tutorial

Object Oriented PHP tutorial

Public, Private and Protected.

Object PHP Security Guard

Security can be addressed better when writing code using object oriented PHP. Access levels can be tightly controlled using Public,Private and Protected methods and Properties.

A Public declared method or property can be accessed via the object anywhere in your script. A Protected method or property can be accessed in the class it is declared within and any subsequent class that extends the initial class. A Private method or property can only be accessed from within the class where the declaration was made.

Note that private or protected properties inside a class are normally declared with an underscore in front of the variable/property name. Examples:

$_name; $_myVar; $_yourVar;

Public properties or variables are not normally declared without an underscore. Examples:

$aVar; $anotherVar; $yetAnotherVar;

Classes are normally declared with a capital letter at the beginning to note it is a class. Examples:

Class Quadruped Class Dog Class Yorkie

$Doggie = new Yorkie();

Next we are going to look at a more comprehensive example. << Previous Page | Next Page > > Article by J C Green This article was written for non-profit educational purposes. Comments? Suggestions? Rants or raves? E-mail me using the form on this website.