Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Object-Oriented PHP Basics (Retired) Inheritance, Interfaces, and Exceptions Object Inheritance

piotr nowik
piotr nowik
Courses Plus Student 560 Points

Hi there. Is it possible to do the "parent" extension in the Soda class on the getInfo() function as on __construction?

if we could "extend" the __construct method, surely we can do the same with the getInfo() method. How can we do that?

2 Answers

You can use "parent::getInfo();"

public function getInfo(){ return parent::getInfo() . "Flavor: " . $this->flavor; }

This would have outputted the same result.

you can just override the getinfo() method in the subclass.. i am not sure where the problem is?

piotr nowik
piotr nowik
Courses Plus Student 560 Points

Hello. Thanks for your answer. There isn't any problem. I was just curious whether you can use the "parent::getInfo()" the same way as with the __construct method. If you can avoid rewriting the constructor function with parent::, why not implement the same thing to other function? That it.