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 Object-Oriented PHP Basics Building the Recipe Static

Keegan Kemp
Keegan Kemp
1,986 Points

Having trouble with this challenge task.

I am working on a challenge task in PHP Basics 2. Im not sure how to get the desired output.

index.php
<?php

class Render {
    public static function displayDimensions($size)
      {
        return implode(" x ", $size);
      }

    public static function detailsRoom($room)
      {
        function getName($name)
          {
            return $name;  
          }

        function getDimensions($size)
          {
            return self::displayDimensions();

          }

        $room = $name . "Dimensions: " . $size;



      }

    echo detailsRoom();
}

?>

1 Answer

Steven Parker
Steven Parker
231,186 Points

Looks like you got a little off track. The instructions weren't asking you to write getName or getDimensions methods, they were just letting you know that they exist in the $room object in case you wanted to use them to create the return string.

And don't forget that the instructions say to return that string instead of assigning it back to the argument or echoing it.

Keegan Kemp
Keegan Kemp
1,986 Points

Thank you for answering. I tried a different approach, but it says getDimensions in not defined?

<?php

class Render 
  {
    public static function displayDimensions($size)
      {
        return implode(" x ", $size);
      }

    public static function detailsRoom($room)
      {
        return $room->getName()." "."Dimensions:".self::displayDimensions(getDimensions($room));
      }
  }

?>
Steven Parker
Steven Parker
231,186 Points

The syntax for calling it should be like what you used for getName.
So instead of getDimensions($room), it would be $room->getDimensions().

Fix that, plus one minor spacing issue, and you'll have it.

Keegan Kemp
Keegan Kemp
1,986 Points

I got it! Thank you very much for your help!