D
D
Dmitriy2019-12-24 20:18:20
PHP
Dmitriy, 2019-12-24 20:18:20

Why will output Fatal Error?

abstract class First {
    private $a = 5;

    abstract public function getVar();
}

class Second extends First{
    public function getVar()
    {
        return $this->a;
    }
}

$obj = new Second();
$obj->getVar();

I pass the test, there is such a question, the answer options are:
  • 5
  • Notice about trying to gain access to unknown authority
  • nothing
  • fatal error

The correct one is Fatal error .
I only thought of Notice .
Why Fatal?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2019-12-24
@dmitriyuvin

The $this->a property is declared private. Therefore, it will not be available in child classes.
But in general it is Notice. At least on php 7.1 (I checked)

I
Ivan Kolotilkyn, 2020-01-04
@asurahan

notice if a variable is declared. and fatal if there is no class property. And you have your own class property that is missing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question