How can one access a parent class property in PHP?
To access a parent class property in PHP, you can use the `parent` keyword followed by `::` to access the property directly. This allows you to retrieve the value of a property defined in the parent class within a child class.
class ParentClass {
public $parentProperty = "I am a property from the parent class.";
}
class ChildClass extends ParentClass {
public function getParentProperty() {
return parent::$parentProperty;
}
}
$child = new ChildClass();
echo $child->getParentProperty(); // Output: I am a property from the parent class.