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 trialVenelin Kovachev
3,431 PointsProblem with my object in code challenge
This is my code. So I can't assign value of 17 on the property number. This is the message that it shows in the preview mode: "Fatal error: Call to undefined method PalprimeChecker::number() in palprimes.php on line 5"
<?php
include("class.palprimechecker.php"); $checker = new PalprimeChecker(); $checker -> number('17');
echo "The number " . $checker; echo "(is|is not)"; echo " a palprime.";
?>
2 Answers
Myroslav Tkachenko
10,581 PointsYou need to assign a value to an object's property with an assignment operator:
$checker->number = 17;
Venelin Kovachev
3,431 PointsI don't know, because they give me only the object name PalprimeChecker and in the next step they ask me to assign value to the propery called number. I tried to make it that way $checker -> PalprimeChecker(17);, but again it doesn't work
Muhammad Mohsen
Courses Plus Student 10,843 Points$checker = new PalprimeChecker;
$checker->number = 17;
then within the echo part
echo "The number $checker->number";
Venelin Kovachev
3,431 PointsIt works! Thank you very much!
Muhammad Mohsen
Courses Plus Student 10,843 PointsMuhammad Mohsen
Courses Plus Student 10,843 PointsDo you have that method called number() in your PalprimeChecker class?