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

Chris Hummel
Chris Hummel
13,960 Points

These instructions are kind of confusing. Can someone help clarify the ask here?

detailsRoom should accept a single object parameter named $room. The $room object will have the follow methods:

getName: will return a string

getDimensions: will return and array of size integers

Add a return value to the detailsRoom method that displays "name Dimensions: length x width", where name is returned from the room getName method and length x width is returned from the render displayDimensions method.

You will need to call the static method displayDimensions from within the Render class and pass the dimensions from the $room object using the getDimensions method

Final Output Example: Kitchen Dimensions: 12 x 14

Am I supposed to be making the getName and getDimensions methods? Do I need to be making a room class? It's worded kind of funky, and I'm having a really hard time deciphering the ask here.

index.php
<?php

class Render {

  public function getDimensions()
  {
    return $self->displayDimensions;
  }

  public function getName()
  {

  }

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


}
?>

2 Answers

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

Hi there, Chris Hummel ! This part of the challenge is trying to tell you that somewhere there is another class file that you can't see that makes a Room. The $room is an instance of that class and will be sent in as a parameter. It's only asking you to make the detailsRoom method.

The Room class which exists elsewhere has a method called getName() and getDimensions. You will use the getName() which returns a string like "Kitchen" and the getDimensions() which returns an array like [14, 12] where the numbers are the length and the width. You're going to need that so that you can send in that array to the displayDimensions method as the $size.

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

First we use the getName method on the Room object that was passed in. Then we do a bit of concatenation for the " Dimensions: " part, and one more concatenation. This time, we're calling the displayDimensions which is a method in the same class and because it's static, you will need to use self:: here. Then we pass in the dimensions that were returned from the Room object's getDimensions, which should be an array with two numbers.

Hope this helps! :sparkles:

Jaroslav Bílek
Jaroslav Bílek
9,409 Points

The introduction in this form is much more human than the original one. Thanks

Josh Coast
Josh Coast
5,112 Points

Thanks Jennifer Nordell, they should have stated the question that way! It's so vague to me as a novice. Like Jaroslav, I thought I had to write the other class and objects.

Josh Coast
Josh Coast
5,112 Points

@Jennifer Nordell Just a note, there's a typo in the question on the test.

"The $room object will have the follow methods:" should be "following"