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

Venelin Kovachev
Venelin Kovachev
3,431 Points

Problem 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.";

?>

Do you have that method called number() in your PalprimeChecker class?

2 Answers

Myroslav Tkachenko
Myroslav Tkachenko
10,581 Points

You need to assign a value to an object's property with an assignment operator:

$checker->number = 17;
Venelin Kovachev
Venelin Kovachev
3,431 Points

I 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

$checker = new PalprimeChecker;

$checker->number = 17;

then within the echo part

echo "The number $checker->number";
Venelin Kovachev
Venelin Kovachev
3,431 Points

It works! Thank you very much!