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!
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
Eric C7,998 Points
when i comment out the php variable $location = "Orlando, FL" in workspaces, the preview has Undefined Variable error
Notice: Undefined variable: location in /home/treehouse/workspace/index.php on line 24
I don't see this error in the video, is this normal?
If you look closer at your code you will see that this variable $location were used to display string in html.
<h1><?php echo $name ?></h1> <p><?php echo $location ?></p>
When you comment or remove a variable declaration you will eventually receive such kind of error. Because when you call it, it holds nothing in it and php interpreter tells you that this variable is undefined. To remove this error, you should declare it and assign value to it, in order to receive proper output. In your case, you just need to remove comment and everthing will work as before ;)
I think the Workspace Hampton is using must have error reporting turned off server side which results in no error message appearing when you try to call $location.
Adding the line
error_reporting(0); to the top of your PHP code will reflect the results that Hampton has but I would recommend against turning it off for learning purposes as it won't alert you to problems with your code.
<?php error_reporting(0); // This is my first name $name = "Mike"; // $location = "Orlando, FL"; $full_name = "Mike The Frog"; $name = $full_name; ?>
As far as I can see in your workspace, you still have those comments in code.
Just remove them on line 7:
//$location = "Orlando, FL";
Without comments it will be simple variable declaration:
$location = "Orlando, FL";
And you will see the output ;)