Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website (2018) Adding a Basic Form Objects

Cliff Jackson
Cliff Jackson
2,886 Points

Can't assign object to variable?

can't seem to assign the value not sure what is wrong?

palprimes.php
<?php
include ("class.palprimechecker.php");
$checker->value = 'PalprimeChecker';





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

?>

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Cliff Jackson ! I feel like you're missing what they're asking here. We use the arrow (->) when we're referring to a property on an instance of an object. In your code, you are trying to assign the string "PalprimeChecker" to the value property of some instance of some object. But you haven't yet made`an instance of an object, which is what this task is asking for.

$checker = new PalprimeChecker;

This declares a variable named $checker and will hold a new instance of the PalprimeChecker as an object. Thus, the value of the variable is a new instance of an object.

Hope this helps! :sparkles:

Cliff Jackson
Cliff Jackson
2,886 Points

Thanks Jennifer, i did not quite understand the question properly, thinking it was object related as covered in previous videos. Similar to assigning functions then but with the 'new' inserted before.?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Cliff Jackson ! It is object related. That is what the new keyword does. It creates a new instance of that object. Let's say for example that the object is a student and that student has a name, a grade point average, a birthdate etc. For each individual student, you would need to make a new instance of an object of the "Student" class.

At about 1:30 of this video you can see the creation of a new instance of PHPMailer which is then assigned to the variable $mail.