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

Can't understand what's wrong...the code perfactly works in workspaces...

Can't understand what's wrong...the code perfactly works in workspaces...

index.php
<?php

class Render {

    public static function displayDimensions($size)
    {
      $output = $size["length"] . " x " . $size["width"];
      return $output;
    }
$size = ["length"=>12, "width"=>14];
echo (Render::displayDimensions($size));
}

?>

4 Answers

Joseph Kato
Joseph Kato
35,340 Points

Hi Dmitriy,

Your code looks okay to me, but I think the following lines are not part of the challenge:

<?php
$size = ["length"=>12, "width"=>14]; // remove this?
echo (Render::displayDimensions($size)); // and this?
?>

Hi Joseph! I tried with or without that lines you refer to. And other variations of code that works as well. But always getting the same mistake!

Joseph Kato
Joseph Kato
35,340 Points

Hmm, interesting.

When I try the challenge with the code in your original post, I get the following error: "Bummer! syntax error, unexpected '$size' (T_VARIABLE), expecting function (T_FUNCTION) in index.php on line 10." Is this what you're experiencing?

Once I remove the two lines I mentioned above, I'm able to pass the challenge.

Joseph I've got this message : Bummer! You must return the dimensions using the $size parameter.

The same thing without that last lines of code... Did you pass the challenge with the same code I have?

Joseph Kato
Joseph Kato
35,340 Points

Oh, sorry -- I think I misunderstood.

I'm able to pass Task 1 (of 4) with the code in your original post (minus the aforementioned two lines), but it appears that you're actually working on Task 2? If this is indeed the case, I think the issue is that you're using strings to index $size when you want to use integers instead (since we're working with a regular array, not an associative array). See below:

<?php
class Render {

    public static function displayDimensions($size) {
      // Note the use of 0 and 1 instead of "length" and "width".
      $output = $size[0] . " x " . $size[1]; 
      return $output;
    }
}
?>

You are right Joseph! It's not an associative array. I changed that indexes like in your code and it works now! Mate thank you a lot for your help!)