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 Interfaces

cynnimon
cynnimon
4,001 Points

How is "parent::price" the answer in the following quiz?

In the quiz after this video, a question asks how to properly access the "price" property of a parent class. I don't understand why "parent::price" is correct, isn't that syntax for accessing static variables only? Why does "price" not have a "$" in front of it if that's the case?

I thought the correct answer would be "parent -> price" but it was not. I am very confused.

3 Answers

Cynnimon,

Using parent:: has always been the customary way to access the parent class from classes that inherit the parent. Here and here are how php.net explains things. As Ted specified, I too believe that the $ is an error with the quiz as in the past I've used the $ to access parent properties.

Cheers!

cynnimon
cynnimon
4,001 Points

Thank you!! After reading those pages it cleared things up. I was confused since the quiz didn't specify if "price" was a static variable.

Based on the video prior to the one that is linked, I think you may have found an error in the quiz. I think the proper answer should be parent::$price. He clearly states that the object operator does not work in that video, but his example includes the $. I will have to play with this more when I have some time.

I sent support@teamtreehouse.com a message referencing this post regarding the error.