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
Joakim Andersson
Courses Plus Student 2,714 PointsCode Challange: Objects
Hello!
Im stuck on Objects part 2/3.
I have no idea how to assign a value to the new class PalprimeChecker.
This is my code so far:
<?php
include("class.palprimechecker.php");
$checker = new PalprimeChecker;
echo "The number ## ";
echo "(is|is not)";
echo " a palprime.";
?>
Could someone hint me on how to add values to the object?
Joakim Andersson
Courses Plus Student 2,714 PointsPalprimeChecker objects have a property called number. This task has two parts. First, assign that property a value of 17. Second, remove the two hash signs (##) in the first echo statement and instead concatenate the value of this number property. (Be sure to preserve the space after the two hash signs by concatenating a space after the number.)
This is the new issue, i dont have a clue how to print the number out..
2 Answers
Randy Hoyt
Treehouse Guest TeacherHey Joakim Andersson , If you had the number in a simple variable, you would print it out like this:
echo $number;
You can use a property in an object just like a variable, including with the echo statement, like this:
echo $checker->number;
Does that help?
Joakim Andersson
Courses Plus Student 2,714 PointsYes, i solved it after some research :) thanks for the help!
Xander Taylor
12,390 PointsIn every new programming language I learn I feel like I track really well until I get to objects... Well, OK, I guess that's only JavaScript and PHP that's happened with but still! Thanks for the help on this one Randy Hoyt... I was really stuck!
Joakim Andersson
Courses Plus Student 2,714 PointsJoakim Andersson
Courses Plus Student 2,714 PointsSolved this by looking at http://php.net/manual/en/sdo.sample.getset.php