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

Jeff Styles
Jeff Styles
2,784 Points

Achieving desired output, but can't pass challenge!!!

I have tried this in a variety of ways and can display the array dims accordingly. However, I am denied passing the challenge and am issued error msgs such as "The displayDimensions method should return the values of the size array" or given a reminder that the array is 0 indexed.

In my opinion, this objective is worded in a terribly ambiguous manner. Do they want me to create a $size array myself? Am I to call the displayDimension method myself? Or, should I just write the return output for the method? I am frustrated as I have spent an hour and a half on a two minute objective.

I have shown in my below code multiple ways I have attempted this. Please someone kindly advise.

index.php
<?php

class Render {

public static function displayDimensions($size) {

  $output = "";   
  $output = $size[0] ." X ". $size[1];
  return $output;    
  }
}
//above code produces output of "12 x 14"
class Render {

  public static function displayDimensions($size) {

    $output = "";
    $output = implode(" X ", $size);
    return $output;
  }
}
//above code produces output of "12 X 14"

$size = [12, 14];
echo Render::displayDimensions($size);
//I have tried this challenge both with and without creating the $size array and calling the function myself
?>

1 Answer

For the first part of the challenge, you're doing too much work. Simply return a concatenated version of the array.

<?php
class Render {
    public static function displayDimensions($size)
    {
      return $size[0] . " x " . $size[1];
    }
}

Then later you'll go on to use the displayDimensions method in another function. When you get there, pay attention to the fact that the $room object you're being provided in the background has a getter method to use in order to access its private properties