LoginSignup
0
0

More than 5 years have passed since last update.

クラス内でのアクセス権とは

Last updated at Posted at 2019-01-06

いきなり結論

アクセス権は3種類。
「public」「private」「protected」

public

どこからでもアクセス可能。

private

そのクラス内からのみアクセス可能。
子クラスからのアクセスは不可。

protected

そのクラスと、親子クラスからのみアクセス可能。

ついでにPHPでの記述例

public
class Hoge {
  public $hoge; //プロパティ
  public function sayHi(){ //メソッド
    return hoge;
  }
}
private
class Hoge {
  private $hoge; //プロパティ
  private function sayHi() { //メソッド
    return hoge;
  }
}
protected
class Hoge {
  protected $hoge; //プロパティ
  protected function sayHi() { //メソッド
    return hoge;
  }
}

簡単ですが以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0