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 trialEvan Hoyt
8,703 PointsPHP Objects Challenge Task 4
I am really confused as to this question, and cannot get past it. I need to assign the property (numbers) of PalprimeChecker a value of seventeen, and I cannot pass the stage.
<?php
include("class.palprimechecker.php");
$checker = new PalprimeChecker(
$checker["number"] => 17;
)
echo "The number " . $checker["number"] ;
echo "(is|is not)";
echo " a palprime.";
?>
1 Answer
Erik McClintock
45,783 PointsEvan,
This can definitely be a tricky task, but it seems it may best suit you to go back and rewatch some videos to try and make sure you've got placement and syntax for things down. In the meantime, here are the errors in your code:
1) Do not place your property assignment inside of the parenthesis of the PalprimeChecker, and make sure you close your statement with a semi-colon
You have:
$checker = new PalprimeChecker(
$checker["number"] => 17; // this is inside of PalprimeChecker - we don't want that
) // no semi-colon present - we don't want that
You need:
$checker = new PalprimeChecker(); // semi-colon present
$checker["number"] => 17; // assignment outside of PalprimeChecker
2) To access properties on an object in PHP, use the single arrow ( -> ) character, and then an equals sign ( = ) to assign it a value
You have:
$checker["number"] => 17;
You want:
// note the -> character to access the number property of the $checker object, and the = to assign the value
$checker->number = 17;
3) Make sure you use the -> syntax in your echo statement, as well, and then concatenate another space character after it
You have:
echo "The number " . $checker["number"] ;
You want:
echo "The number " . $checker->number . " ";
Erik
Evan Hoyt
8,703 PointsEvan Hoyt
8,703 PointsThank you so much. It worked!