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 Simple PHP Application Wrapping Up The Project Objects

PHP Objects Challenge Task 4

I am really confused as to this question, and cannot get past it. I need to assign the property (numbers) of PalprimeChecker a value of seventeen, and I cannot pass the stage.

palprimes.php
<?php

include("class.palprimechecker.php");

$checker = new PalprimeChecker(
$checker["number"] => 17;
)

echo "The number " . $checker["number"] ;
echo "(is|is not)";
echo " a palprime.";

?>

1 Answer

Erik McClintock
Erik McClintock
45,783 Points

Evan,

This can definitely be a tricky task, but it seems it may best suit you to go back and rewatch some videos to try and make sure you've got placement and syntax for things down. In the meantime, here are the errors in your code:

1) Do not place your property assignment inside of the parenthesis of the PalprimeChecker, and make sure you close your statement with a semi-colon

You have:

$checker = new PalprimeChecker(
    $checker["number"] => 17; // this is inside of PalprimeChecker - we don't want that
) // no semi-colon present - we don't want that

You need:

$checker = new PalprimeChecker(); // semi-colon present

$checker["number"] => 17; // assignment outside of PalprimeChecker

2) To access properties on an object in PHP, use the single arrow ( -> ) character, and then an equals sign ( = ) to assign it a value

You have:

$checker["number"] => 17;

You want:

// note the -> character to access the number property of the $checker object, and the = to assign the value
$checker->number = 17;

3) Make sure you use the -> syntax in your echo statement, as well, and then concatenate another space character after it

You have:

echo "The number " . $checker["number"] ;

You want:

echo "The number " . $checker->number . " ";

Erik

Thank you so much. It worked!