LoginSignup
0

More than 5 years have passed since last update.

継承とスコープ定義演算子の影響について

Posted at
php

<?php

class First
{
  const test = 'first';
  protected static $_test = 'first';

  public static function getConst()
  {
    return static::test;
  }

  public static function getVar()
  {
    return static::$_test;
  }
}

class Second extends First
{
  const test = 'second';
  protected static $_test = 'second';
}

class Third extends Second
{
}

var_dump(First::getConst());
var_dump(Second::getConst());
var_dump(Third::getConst());

var_dump(First::getVar());
var_dump(Second::getVar());
var_dump(Third::getVar());

実行結果

string(5) "first"
string(6) "second"
string(6) "second"
string(5) "first"
string(6) "second"
string(6) "second"

Thirdがどういう出力になるのかが分からなかったので備忘録

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