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 trialDustin Mordica
7,871 PointsPlease explain why the index page needs to have the $section = null;
If we load the index.php page and comment out "$section.php = null;" why are all of the links underlined?
Shouldn't it still include/load the header.php file and find that
<li class="books<?php if ($section == "books") {echo " on";} ?>"><a href="catalog.php?cat=books">Books</a></li>
is false? Because the $_GET["cat"] was never set from the index.php file.
Therefore it shouldn't append the " on" class correct? Yet by default it underlines the links? Maybe there is something I am missing within the CSS file but I removed the php script from the list items and it then removed all of the underlines.
Thoughts?
1 Answer
Seth Kroger
56,414 PointsWhen you comment out the $section = null; in index.php, when you get to the header $section will still be undeclared/undefined. Because it's undefined, it causes an error when you try to access it. What happens with the error depends on the server's settings. On Workspaces you'll get this output:
<li class="books<br />
<b>Notice</b>: Undefined variable: section in <b>/home/treehouse/workspace/includes/header.php</b> on line <b>15</b><br />
">
Note that the error message includes the word "on".
Dustin Mordica
7,871 PointsDustin Mordica
7,871 PointsThats kind of what I kind of figured. I assumed if I could set the server side settings it would have thrown a warning or something. It just seemed odd that when an undefined variable is compared that it would automatically set the comparison to true.
Thanks!