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
Alejandro Carrillo
1,781 PointsHelp with the tasl 4/7 in the Objects challenge in Wrapping up the project in PHP
Hi, guys... been looking the video again and again and don't understand how to do this.
First, here's the link to the challenge: http://teamtreehouse.com/library/programming-2/build-a-simple-php-application/wrapping-up-the-project/objects
Then, here's what I've come up to:
<?php
include_once("class.palprimechecker.php");
$checker = new PalprimeChecker;
$checker -> number = 17;
echo "The number " . $number ;
if($number == isPalprime){
echo "is";
}
else {
echo "is not";
}
echo " a palprime.";
?>
Why is wrong?
Thanks
6 Answers
Randy Hoyt
Treehouse Guest TeacherTwo things:
(1) Remember that number is an attribute of the PalprimeChecker object. You are accessing the property correctly when you set it ...
$checker->number = 17;
... but you are not accessing it correctly when you echo it. It should look like this:
echo "The number " . $checker->number;
(2) isPalprime is a method of the PalprimeChecker object. It's a lot like the Send method in the PHPMailer object we look at in the video. Let me show you some examples of that:
// #1. incorrect
if ($message == Send) {
echo "Hooray! The message was sent.";
}
// #2. correct
if ($mail->Send()) {
echo "Hooray! The message was sent.";
}
Your conditional looks like the incorrect example (#1). You want your conditional to look more like the correct example (#2).
Do those two comments help?
Alejandro Carrillo
1,781 PointsYes, man, they helped me a lot... that object stuff is an other "stuff"..
Thanks!
David Jennings
3,704 PointsHi Randy- I have followed the video and I am still getting an error myself
Message:
It doesn't look like you are calling the isPalprime method on the $checker object. You should be calling that method in a conditional to determine if you should display “is” or “is not” on the page.
<code>
<?php
include_once ("class.palprimechecker.php");
$checker = new palprimechecker ;
$checker -> number = 17;
echo "The number " . $checker->number;
if ($number -> isPalprime)
{
echo " is";
}
else
{
echo " is not";
}
echo " a palprime.";
?>
</code>
Can you offer any assistance
Thanks
D
Randy Hoyt
Treehouse Guest TeacherThe line with the problem is this one:
if ($number -> isPalprime)
Two things to note:
- You are referencing a variable called
$numberhere, but you don't have a variable named that anywhere. -
isPalprimeis a method of an object, but this looks like a property.
You'll need to change $number to the name of the variable that is the PalprimeChecker object, and you'll need to add some punctuation to the isPalprime reference so that it calls the method.
Do those tips help?
David Jennings
3,704 PointsGot it Thanks
<?php
include_once ("class.palprimechecker.php");
$checker = new palprimechecker ;
$checker->number = 17;
echo "The number " . $checker->number;
if ($checker->isPalprime())
{
echo " is";
}
else{
echo " is not";
}
echo " a palprime.";
?>
Robert Parsons
1,582 PointsVery helpful! Thank you!
Sherry Parker
9,601 PointsSherry Parker
9,601 PointsThanks! That really helped me out.