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 trialjasonjones5
Courses Plus Student 5,571 PointsWhy is this right?
I completed the challenge to echo the value of the number property by basically reading through the forums and piecing it together but I'm still not happy that I understand the process. Here's the code
<?php
include("class.palprimechecker.php");
$checker = new PalprimeChecker();
$checker->number = 17;
echo "The number " . $checker->number . " ";
echo "(is|is not)";
echo " a palprime.";
?>
I can see we're including the object and then creating a new instance essentially. We then add a value to one of its properties. What I'm not getting is the echo statement. Is that essentially a variable just using different syntax i.e you would always call an object property like this no matter where it appeared?
2 Answers
Sam Roberton
7,225 PointsIn short yes, you can alter and print properties of a class in this way as long as the visibility allows you to. Check out the examples in this link :) http://php.net/manual/en/language.oop5.visibility.php
jasonjones5
Courses Plus Student 5,571 PointsThat got an instant bookmark. Thanks a lot, very useful