i was wondering why there is no $parent->function(); syntax in php, but instead we can use parent::function(); which looks like it’s used inside a static class. Am i missing some php oop basics?
i was wondering why there is no $parent->function(); syntax in php, but instead we
Share
I admit it seems strange — and you didn’t miss anything in the manual ^^
But :
__construct, I admit — that’s probably why it’s said explicitly in the manual that you have to call the parent’s__constructmethod yourself.$thisto call methods in the same instance of either the child or the parent class ; no need to know where the method actually is.parent::works fine, even if it looks like a static callAnd here’s an example of code showing
parent::works fine :You’ll get this output :
Which shows that the method in the parent class has access to
$thisand the properties defined in the child class.