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 trialglen rose
1,182 PointsPHP-OOP - Getter from static class help
Hi
I´m learning PHP OOP and i´m stuck.
The problem is that I need to do this: Challenge Task 4 of 4
The accepted parameter $room will be an object which has a method named getDimensions. Add a return value to the detailsKitchen method that displays "Kitchen Dimensions: length x width", where length x width is returned from the displayDimensions method. You will need to call the static method displayDimensions from within the Render class and pass the dimensions from the $room object using the getDimensions method Final Output Example: Kitchen Dimensions: 12 x 14
My code is:
<?php
class Render {
public static function displayDimensions($size)
{
$word0 = $size[0];
$word1 = $size[1];
return $word0 . " x " . $word1;
}
public function getDimensions (){ $room = "Kitchen Dimensions: "; $room .= $self->word0; $room .= " x "; $room .= $self->word1; }
public static function detailsKitchen ($room){ return $room; }
}
?>
THE ERROR CODE SAYS IT can't convert $Room to a string.....
Thanks :-)
2 Answers
filipepacheco
Full Stack JavaScript Techdegree Student 21,416 PointsHi, glen rose,
You don't need to create the getDimensions method. What they meant is that the $room parameter already is an object and this object already has the getDimensions method. So you would use it like this within the detailsKitchen method $room->getDimensions().
In the detailsKitchen method you just need to return "Kitchen Dimensions: length x width". Remember that the displayDimensions method is already like length x width, so you do: return "Kitchen Dimensions: " . self::displayDimensions() ;
It's still not going to work, because the displayDimensions method accepted a parameter, which are the exactly numbers for the length and width. You get these numbers through $room->getDimensions(). So you add that as a parameter. Have a look at my code.
class Render {
public static function displayDimensions ($size)
{
return "$size[0] x $size[1]";
}
public static function detailsKitchen ($room)
{
return "Kitchen Dimensions: " . self::displayDimensions($room->getDimensions()) ;
}
}
glen rose
1,182 PointsAhhhhh now I see....
I think it gets hard to follow using an object in the parameter displayDimensions.....
But I get it now.
Thanks for the help :-) !!!