M
M
Max Ba2018-12-07 11:13:58
PHP
Max Ba, 2018-12-07 11:13:58

Why is the property not available on the heir?

Guys, help me understand. Why the heir does not see the variable "year".

class Class1{
  
  protected $year = 1;
  
  public function setYear($year){
    $this->year = $year;
  }
  
}

class Class2 extends Class1{
  
  public function getYear(){
    return $this->year;
  }
  
}

$class1 = new Class1();
$class1->setYear(2018);


$class2 = new Class2();
echo $class2->getYear(); //NULL

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2018-12-07
@Rsa97

Strange, I can see everything, returns 1, as it should be.

Y
yurybykov, 2018-12-08
@yurybykov

Try rearranging PHP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question