LoginSignup
0
0

More than 3 years have passed since last update.

[PHP] selfとstaticの違いメモ

Posted at

要点

self: 定義時のクラスを指す
static: 実行時のクラスを指す

class Foo
{
    public function helloGateway()
    {
        self::hello();
    }

    public static function hello()
    {
        echo __CLASS__ . 'hello' . PHP_EOL;
    }
}

class Bar extends Foo {
    public static function hello()
    {
        echo __CLASS__ . 'hello' . PHP_EOL;
    }
}

$bar = new Bar();
echo $bar->helloGateway();
//この場合はFoohelloが出力される
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