PHP5 allows developers to create public , private and protected methods and properties. They can be defined as :-
Protected:- The specified class and subclasses of that class can use the methods of that class
protected class Test
{
$dead = false;
function human()
{
}
function set($dead)
{
$this->dead = "true";
}
}
Public:- The specified class can only use the methods of that class no subclasses can modify the contents of that class
public class Test
{
$dead = false;
function human()
{
}
function set($dead)
{
$this->dead = "true";
}
}
Private:- The specified class can use the methods of that class, No Subclasses can use any method of that classes !
private class Test
{
$dead = false;
function human()
{
}
function set($dead)
{
$this->dead = "true";
}
}
It’s a good idea to mark functions and classes as protected , This can future proof the code because no method can change the value outside from the class thus reducing the number of hacking attempts.
{ 1 comment… read it below or Shout @ me! }
New Blog post:- Difference between Public, Private and protected classes | PHP tutorials and Scripts Collection http://bit.ly/rAaPZ
This comment was originally posted on Twitter