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

Totally stuck

Hope you guys can see my code....

I tried different things but didn't came up with a solution... This task description seems a little vague in my opinion, maybe it's just because I speak dutch ...

index.php
<?php
class Render {

    static function displayDimensions($size)
    {
      return $size[0] ." x ". $size[1];
    }
    static function detailsKitchen($room)
    {
      return "Kitchen Dimensions: " .$self::displayDimensions($room->getDimensions());
    }
    static function getDimensions()
    {
      return array(12,14);
    }

 $newRoom = new Render

$newroom->detailsKitchen($newroom);

}
?>

1 Answer

Robert Leonardi
Robert Leonardi
17,151 Points

HI Wouter,

You should fix your code

  1. to display output , you should use "print_r" or "echo"
  2. closed bracket of class Render was misplaced
  3. you forgot ";" on new Render
  4. you don't need input for detailsKitchen, just call the function
  5. you can call function within the class by just using "$this->name_of_function"
  6. change all "static" to "public"

try this

class Render {

    public function displayDimensions($size)
    {
      return $size[0] ." x ". $size[1];
    }
    public function detailsKitchen()
    {
      return "Kitchen Dimensions: " .$this->displayDimensions($this->getDimensions());
    }
    public function getDimensions()
    {
      return array(12,14);
    }
}
$newRoom = new Render;
print_r($newRoom->detailsKitchen()); // display output
?>

Oups... I didn't realize this is a code challenge.... You should use "self::" instead of "$self::"

it becomes

class Render {

    static function displayDimensions($size)
    {
      return $size[0] ." x ". $size[1];
    }
    static function detailsKitchen()
    {
      return "Kitchen Dimensions: " .self::displayDimensions(self::getDimensions());
    }
    static function getDimensions()
    {
      return array(12,14);
    }
}
$newRoom = new Render;

print_r($newRoom->detailsKitchen());

?>

Hope it helps