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 trialAlfredo Prince
6,175 PointsWhat's wrong with this code? Why can't I use $room as an array?
Help me a little bit with this final task. Am I going for a good route? What should I do ? Please help me understand this a little more.
<?php
class Render {
public static function displayDimensions($size)
{
return $size[0] . " x " . $size[1];
}
public static function getDimensions($room)
{
return $size->room;
}
public static function detailsKitchen($room)
{
return "Kitchen Dimensions: " . $room[0]->displayDimensions. "x" . $room[1]->displayDimensions;
}
}
?>
2 Answers
Bryan Manhollan
Courses Plus Student 10,096 PointsBeen a long time since I did php. But I think your issue is where you return to room.
return $size->room
should be return $size->$room
Bryan Manhollan
Courses Plus Student 10,096 PointsSpacing is wrong.
<?php
class Render {
public static function displayDimensions($size)
{
return $size[0] . " x " . $size[1];
}
public static function getDimensions($room)
{
return $size->room;
}
public static function detailsKitchen($room)
{
return "Kitchen Dimensions: " . $room[0]->displayDimensions. "x" . $room[1]->displayDimensions;
}
}
?>
Alfredo Prince
6,175 PointsAlfredo Prince
6,175 PointsThank you! I tried your solution but it's still marking an error here on line 17: Uncaught Error: Cannot use object of type Room as array in index.php:17