MORE INFORMATION
EDIT: This question seems to relate to a predefined project available at an educational site. The OP seems to be confused as to why the exact same code fails on some servers, and seems to work others. They were thinking it was something to do with the PHP version. It is more likely as a result of the suppression of warnings server side. To suppress warnings you could simply add:
error_reporting(E_ERROR | E_PARSE);
However; it would be far better to define or test the variable properly [in this case $section] and not simply mask the issue.
Using a PHP variable called $section along with a CSS selector of the same name will work
..Just because you can do something, doesn't mean you should..
Anyway, it is not a CSS error per se, but it certainly doesn't help in this circumstance.
Take note that the error/warning in your code has the word section
in it:
<li class="shirts <br /> <b>Notice</b>: Undefined variable: section .....">
Both examples have a CSS style called section.shirts
:
.section.shirts {
background: none repeat scroll 0 0 #FFFFFF;
padding-bottom: 42px;
}
As a result of the placement of the error/warning, most browsers will interpret your class as to include any of the words found within the quotes (eg; shirts
undefined
section
etc) and apply them all as styles if found in your CSS. In your version of the page, as a result of the placement of the error, you are applying the styling above. The other site does not have an error/warning with the word section
within double quotes inside a class so it does not apply that particular styling.
There is no correlation between PHP variables and CSS selectors (read: There is no conflict between PHP Variables and CSS Selector Names/variables in current, older or dare I say it, future versions of PHP) with the same name unless you generate an error in your resultant HTML in an unfortunate position. In this case, you have done this by creating an error between double quotes inside a class.
Fix your error and your styling will apply as expected. No bug here (other than line 17 in your code :)
Without seeing your code, to fix your error/warning:
[Unlikely] Maybe add a $ in front of section
where applicable in your code if it is missing somewhere (like this $section
)
Maybe ensure you are defining $section before you test it in your if statements
Maybe Use isset when testing $section if you don't know if it was previously initialized.
So in summary, the word section is rendered inside your HTML within an error/warning and interpreted as part of your CSS class structure as discussed.
Why does it work on older versions of PHP?
If you are wondering why it works in other environments, have you considered that maybe it has nothing to do with the PHP Version - Perhaps in other environments with the same error/warning, they have configured PHP to suppress the display of errors and or warnings.
Without the error, the word section
would not appear inside your class; ergo - no style issue.
From the PHP Manual:
Relying on the default value of an uninitialized variable is
problematic in the case of including one file into another which uses
the same variable name. It is also a major security risk with
register_globals turned on. E_NOTICE level error is issued in case of
working with uninitialized variables, however not in the case of
appending elements to the uninitialized array. isset() language
construct can be used to detect if a variable has been already
initialized.
For more information about your particular error, see this previous answer.