10
14

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 5 years have passed since last update.

【Laravel】静的メソッドと動的メソッドについて

Posted at

#静的メソッド

public static functionで定義されるメソッド。

self::メソッド名で呼び出す時に利用する。

#動的メソッド

public functionで定義されるメソッド。

$変数->メソッド名で定義される。

#使い方

sample.php
public static function foo()
{
    return 'hello';
}

public function bar()
{
    return 'world';
}
SampleController.php
public function index()
{
    $sample = Sample::foo();

    $bar = new Sample;
    $sample = $bar->bar();
}

静的メソッドはクラスから呼び出す。
動的メソッドはインスタンスから呼びだす。

10
14
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
10
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?