1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

php オブジェクトで使われる用語

Last updated at Posted at 2022-12-15

①クラス

class Post
{
private $text //プロパティ

  public funtction show() //メソッド
  {
    printf($this->text);
  }
}

$posts = new Post('hello'); //インスタンス

・クラスの中で宣言した変数「プロパティ」
・クラスの中で定義した関数「メソッド」
・クラスからnewして作った値「インスタンス」

クラス内で変数にアクセスするには $this->変数名 とする

②コンストラクタ

class Post
{
private $text //プロパティ

public function __construct($text) //コンストラクタ
{
  $this->text = $text;
}
  public funtction show() //メソッド
  {
    printf($this->text);
  }
}

$posts = new Post('hello'); //インスタンス

・コンストラクタはnewしたときに実行されるメソッド

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?