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 Basic PHP Website (2018) Adding a Basic Form Objects

Cliff Jackson
Cliff Jackson
2,887 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,887 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.