Class Tree · Level 3 of 7

self or static

Model and its child User both have name(). Watch who answers self:: and static::.

<?phpclass Model {    public static function name(): string { return 'Model'; }    public static function selfName(): string { return self::name(); }    public static function staticName(): string { return static::name(); }    public static function create(): static { return new static(); }}class User extends Model {    public static function name(): string { return 'User'; }}echo User::selfName(), "\n";echo User::staticName(), "\n";echo get_class(User::create()), "\n";

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…
  3. 3…