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

Corey Lyons
Corey Lyons
24,684 Points

Object Oriented PHP Static challenge 2 of 4

I am doing this challenge and an error message comes up: Bummer! You must return the dimensions using the $size parameter.

I thought I was doing that any help is appreciated!

index.php
<?php

class Render {

  public static function displayDimensions($size)
  {
    $size = array("length", "width");
   return $size;
  }

}

?>

1 Answer

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

Hi there! The $size is a parameter which means it's an array being sent by another piece of code. That array contains two numbers. The first one is the length and the second is the width. You've taken the information they've sent in and overwritten it with an array that contains two strings "length" and "width". Then you return that array. But they are looking for you to return a string that contains the length and the width they sent in. For example, if they send in an array that looks like [10.2, 15.3], they want a string returned that says "10.2 x 15.3". This is how I did it:

<?php

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

}

?>

This declares a function that accepts an array containing two numbers which represent the length and width. We can access the array elements using subscripting and expand them inside the string using the double quotation marks and then return the resulting string.

Hope this helps! :sparkles:

Corey Lyons
Corey Lyons
24,684 Points

I was over thinking on this challenge thank you!

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

Corey Lyons Here's a little tip. If you get to one of these PHP challenges and you think the instructions are a bit confusing, try adding a line as an echo of a var_dump that will make it obvious what the challenge is sending in. This has helped me now and then. In this instance I would've put:

 echo var_dump($size);

Then click the preview button and it'll show exactly what is being sent to that function :smiley: