Wednesday, December 9, 2009

Access Modifiers

There are 3 access modifiers: Public; Private; and Protected

'Public' is the default modifier.

Public: Use In Everywhere
Private: Use in This class only
Protected: Use in This class and subclass

class Example{
public $a=1;
protected $b=2;
private $c=3;

function show_abc(){
echo $this->a;
echo $this->b;
echo $this->c;

public function hello_everyone(){
return "Hello Everyone"."
protected function hello_family(){
return "Hello Family"."
private function hello_me(){
return "Hello Me"."

function hello(){
$output = $this->hello_everyone();
$output .= $this->hello_family();
$output .= $this->hello_me();

return $output;


$example= new Example();
echo "public a:{$example->a}
//echo "protected b:{$example->b}
//echo "private c:{$example->c}
echo "
echo "hello_everyone: {$example->hello_everyone()}
//echo "hello_me: {$example->hello_me()}
echo $example->hello();

No comments:

Post a Comment

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off