'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}
";
$example->show_abc();
echo "
";
echo "hello_everyone: {$example->hello_everyone()}
";
//echo "hello_me: {$example->hello_me()}
";
echo $example->hello();
?>
source:lynda.com
No comments:
Post a Comment