Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website (2018) Building a Media Library in PHP Adding Active States to the Navigation

Please 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
Seth Kroger
56,392 Points

When 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".

Thats 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!