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) Properties and Methods Mid-Course Challenge

Pablo Grippo
Pablo Grippo
25,765 Points

What is the reference to the current object?

I can't complete the last step, because I can't figure out how I use $this to reference the current object. Please, help me!

I put return "A Largemouth.." . $this->???;

1 Answer

Think about how you wrote your constructor function. Then, when you created a new instance of the Fish object you passed in several values to the constructor function which then assigned the values to the properties in the new $bass object. In effect you were doing this:

$this->common_name = "Largemouth Bass";

and the same for each of the other two values. Use $this along with the object operator (->) and the property name (declared in the class) as a single unit that works just like any other php variable. Then use those variables to construct the string given as the last instruction of the challenge for your return value in the getInfo method. If you're still unclear, let me know.

Pablo Grippo
Pablo Grippo
25,765 Points

I wrote $this->common_name and it works!!!

Thank you so much Joe Hartman! (Y)