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

I don't understand the task 4/4 it is really confusing , please help.

I'm just really confused what im getting from $room and in which way to dispaly it , can someone please explain ..

index.php
<?php

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

  public static function detailsKitchen ($room){

  }
}

?>

1 Answer

Spenser Hale
Spenser Hale
20,778 Points

Hello Boban Rajovic,

I answered another on of your questions. It appears you are having a hard time understanding how to use objects. Please review earlier videos linked with notes below to have a better understanding.

Properties

To read and set from a property of a object use the -> syntax with name, example:

<?php

$object = new stdClass();
$object->count = 0;
$object->count += 1;

$count = $object->count;
// $count would be 1.

Methods

To read from a method of a an object it is same as a property, but with () at the end, example:

<?php

$dimensions = $room->getDimensions();
// $dimensions would be array with two values in array, x and y values, ie [12,14]
$x = $dimensions[0];
// $x would be 12
$y = $dimensions[1];
// $y would be 14

Putting it all together:

<?php

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

    public static function detailsKitchen ($room){
        $size = $room->getDimensions();
        $displayDimensions = static::displayDimensions($size);
        return 'Kitchen Dimensions: ' . $displayDimensions;
    }
}