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

Alex Spataru
Alex Spataru
5,837 Points

Object-Oriented PHP Basics Challenge Task 4 of 4

Hi everyone.

I've made this code (I hope you can see it) and the output is at it should be. However, I cannot go further as it says that the output is wrong :(

Can anybody help me?

Thanks, Alex

index.php
<?php

class Render {

  public static function displayDimensions ($size){

    if(!isset($size[0]) || !isset($size[1])) return '';
    return "$size[0] x $size[1]";

  }

  public static function detailsKitchen($room){

    return "Kitchen Dimensions: " . self::displayDimensions((array)$room) ;
  }

}

echo Render::detailsKitchen(array(12, 14));

?>

1 Answer

Alex Spataru
Alex Spataru
5,837 Points

Ok, I've found this code which make the same output but still, It doesn't seem to be the correct answer...

<?php

class Rooms {

  private $dimensions = array();

  public function getDimensions(){

      return $this->dimensions;

  }

  public function setDimensions($size, $width){

        $this->dimensions[] = $size;
        $this->dimensions[] = $width;  

  }

}

class Render {

    public static function detailsKitchen($room){

      return "Kitchen Dimensions: " . self::displayDimensions($room->getDimensions()); 

    }

    public static function displayDimensions($size){

        $str = "";
        $str .= $size[0] . " x " . $size[1]; 
        return $str;

    }

}

$room = new Rooms();
$room->setDimensions(12,14);
echo Render::detailsKitchen($room);

?>

The errors is

Bummer: You use the keyword "self" instead of "this" when accessing a static method.