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 trial

PHP Enhancing a Simple PHP Application Integrating Validation Errors Reviewing PHP Basics

Kristopher Hutchison
Kristopher Hutchison
2,450 Points

Challenge says $flavor is not being echoed. I'm pretty sure my answer is correct. Could this be a bug?

Not sure why $flavor is not echoing to page. I've even tried placing my echo statement below the return.

output.php
<?php
include_once('flavor.php');
echo "Randy's favorite flavor of ice cream is ".$flavor.".";
$flavor = get_flavor();
return $flavor;

?>

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

The big problem here is that you're trying to echo something you haven't gotten yet. You have to define the flavor variable then call the method that's in the flavor.php file and set the value of flavor to the value returned by that method. The minor thing is that you don't need a return statement at all. Your code isn't wrong per sé... it's just a bit misordered. Take a look at my solution:

<?php
include_once('flavor.php');
$flavor = get_flavor();
echo "Randy's favorite flavor of ice cream is ".$flavor.".";

?>

Moral of the story: in most languages you can't use a variable you haven't defined yet. Happy coding!