parent¶
parent is one of the three special keywords that are used to access properties or methods from inside the class definition. It relates to the first parent class, or any or their own parents. In particular, when searching for methods or properties, it may skip the direct parent, and land on one of the parent above.
Parent represents the first parent of the class.
In a trait, parent represents the host class’s parent, not the trait own parent. In fact, the trait has no parent.
<?php
class W {
protected const X = 1;
}
class X extends W {
function foo() {
// could also be written as \W::C; here
return parent::C;
}
}
?>
Related : Overwrite, static, Self, Late Static Binding