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 trialMatt Nickolls
9,895 PointsA bit stuck on this OOP Basics question. Any help?
The question asks for the instantation of a $room object that has two methods (getName and getDimensions). Does that mean we need to create a room class with these methods? I've got so far with the coding as per the attached, but I'm not sure I'm going the right way.
<?php
class Render {
public static function displayDimensions($size){
$length = $size[0];
$width = $size[1];
return $length . " x " . $width;
}
public static function detailsRoom($room) {
return
}
}
class Room {
private $name;
private $Dimensions;
public function getName {
{
return $this->name;
}
public function getDimensions {
{
return $this->Dimensions;
}
}
?>
1 Answer
Matt Nickolls
9,895 PointsAh no worries, I solved it.....I think...
<?php
class Render {
public static function displayDimensions($size){
$length = $size[0];
$width = $size[1];
return $length . " x " . $width;
}
public static function detailsRoom($room) {
return $room->getName() . " Dimensions: " . self::displayDimensions($room->getDimensions());
}
}
class Room {
private $name = "Kitchen"; private $Dimensions = array(12, 14);
public function getName {
{
return $this->name;
}
public function getDimensions {
{
return $this->Dimensions;
}
}
?>