I have a question about inheritance in php 8.3.
I have an abstract class with a property, variable or what ever it must be called.
I then try to set this property/variable from a function in the abstract class. Then I get an error saying “Undefined variable”
I think that all conventions about OOP has been kept, what am I missing here?
<?php
abstract class grandparent{
public function somefunction(){
}
}
abstract class myparent extends grandparent{
public $prop;
protected function setfunction($myprop){
$this->$prop = $myprop;
}
}
class child extends myparent{
public function myset() {
$this->setfunction(42);
$myvar = $this->prop;
}
}
$myInstance = new child();
$myInstance->myset();