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 Build a Simple PHP Application Wrapping Up The Project Objects

Willie Allison
Willie Allison
2,035 Points

How do you concentrate a number in a value in the PalprimeChecker?

I can't figure out how to use the -> operation to get this code to substitute in the 17 to the echo code.

palprimes.php
<?php

include('class.palprimechecker.php');
$checker= new Palprimechecker(17);
$checker -> ($checker);


echo "The number $checker ";
echo "(is|is not)";
echo " a palprime.";

?>
Blaize Pennington
Blaize Pennington
13,878 Points

Objects can get really tricky. In fact I still have a little trouble with them myself, but they are so useful its worth taking the time to learn.

The first mistake you are making is when declaring a new object, you do not need to pass any variables (You can, but lets stick with the basics); So after you include your file you would want to declare it as:

 $checker = new PalprimeChecker();

Also be sure your casing is correct as variables are case sensitive. Next the challenge is telling you to change the object attribute called "number" to 17. You would do this by adding the single arrow after your object variable into the attribute name.

$objvar = new ObjectWithAttributes();
$objvar->attribute = value;

Above is the basic syntax for this. So your $objvar would be $checker, your "ObjectWithAttributes" would be PalprimeChecker(), And your attribute would be "number".

Then anytime you want to call your new attribute's value you would use:

echo "The number " . $checker->number . " ";

give it a try and let me know if you have any more questions.