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

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.