개발관련/PHP

[PHP]Access Modifiers

파노카페 2012. 4. 20. 15:09
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.
"; } //public by default 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_family: {$example->hello_family()}
"; //echo "hello_me: {$example->hello_me()}
"; echo $example->hello(); ?>
public a: 1
123
hello_everyone: Hello everyone.

Hello everyone.
Hello family.
Hello me.