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 Extending Object-Oriented PHP Inheritance Using Multiple Classes

Alex Bauer
Alex Bauer
9,426 Points

Why is the status premium before Alena made the change to the child class' status?

I don't understand how the status could be premium when using the properties for the parent class especially because it's a private property, and there's no status for the child class. Can someone help me understand what is happening?

theodevries
theodevries
15,895 Points

edited: I added it as answer instead of comment.

2 Answers

theodevries
theodevries
15,895 Points

Hi Alex,

The 'premium' status is set to the property in some of the instances of the object. That is what you see. If you create a new instance yourself it would have 'basic' status as default.

In classes/Collection.php a collection of instances of the ListingBasic class is created. In the collection are instances of the class where the status is set to 'premium', 'basic' or 'inactive'. The data to create the instances is retrieved from a database.

In the class Collection a collection (listing) is created in the selectListings() method. On line 50 each record is added to the collection in the addListing() method. If you place a var_dump($data) inside that for each loop you can nicely see the data. There are some records with premium, inactive and basic statusses. In the addListing() method the instances get created. Through the __construct method of the ListingBasic Class a setValues() method is called where the status (and other data) is set per instance. That's why ListingBasic has premium status.

kind of elaborate. Try to follow the path, starting with index.php. It's kind of informative.

Kind Regards

Alex Bauer
Alex Bauer
9,426 Points

Thank you Theo, for your time and your generosity. I think I understand it. I went through the steps starting from index.php and I understand it more; I think I'm sort of confused by the query in selectListings because some of it is unfamiliar to me as of right now. I believe what your saying is that the premium status was determined by what data is in the database that is associated with a certain id that already was created before I began the course. If I could see the database I think it would make a lot more sense. I'll come back to this post once I understand SQL more and try and make sense of it then.

theodevries
theodevries
15,895 Points

Correct. The info from the database is used in the Collection class to instantiate objects.

If you put the var_dump in the collection class like I said in my answer you will see an output of the data from the database.

Good luck, Alex.