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 trialKeegan Kemp
1,986 PointsOne of my getters won't print when I return this method:
I am working on Object-Oriented PHP Basics and I don't know why one of my getters is not printing when I return the method, because the other ones work fine.
<?php
class Render
{
public static function displayRecipe($recipe)
{
$output = "";
$output .= $recipe->getTitle() . " by " . $recipe->getSource();
$output .= "\n";
$output .= implode(", ",$recipe->getTags());
$output .= "\n";
foreach ($recipe->getIngredients() as $ing){
$output .= $ing["amount"] . " " . $ing["measure"] . " " . $ing["item"];
$output .= "\n";
}
$output .= "\n";
$output .= implode("\n", $recipe->getInstructions());
$output .= $recipe->getYield();
return $output;
}
}
Here is a link to my workspace snapshot: https://w.trhou.se/c9hsuj7vvr
Thank you very much for your help.
2 Answers
Steven Parker
231,269 PointsI don't think there's a problem with the code shown above, but luckily everything is in the snapshot.
You forgot to mention which "one of" you were having trouble with, but on first glance it looks like on line 57 of recipes.php, addInstruction loads a string into "instruction" (singular), but on line 64 getInstructions returns "instructions" (plural).
Does fixing that clear up the issue?
Keegan Kemp
1,986 PointsThat worked, thank you!
Keegan Kemp
1,986 PointsKeegan Kemp
1,986 PointsI thought that might be the issue at first, but the addIngredient method is formatted that same way and works fine. And that is the way it is done in the video as well.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYou didn't link this question to the course page, so I couldn't check the video. But in your snapshot, the getter/setter for ingredients both use the same variable name spelling. Lines 42 and 51 both have
$this->ingredients
(plural).To make instructions work the same, line 57 needs the letter "s" added to the variable name to make it match line 51.