I got some legacy code that has this:
<?PHP if(isset($_GET['pagina'])=='homepage') { ?> HtmlCode1 <?php } else { ?> HtmlCode2 <?php } ?>
I don’t know exactly why but this seems to be working. The htmlcode1 is loaded when I have ?pagina=homepage and the htmlcode2 is loaded when the pagina var doesn’t exist or is something else (haven’t really seen with something else, just not there). The website is using php4 (don’t know the exact version). But really, how can this work? I looked at the manual and it says isset returns a bool..
Anyone?
The problem is that "==" isn’t a type-sensitive comparison. Any (non-empty) string is "equal" to boolean true, but not identical to it (for that you need to use the "===" operator).
A quick example, why you’re seeing this behavior:
http://codepad.org/aNh1ahu8
And for more details about it from the documentation, see:
http://php.net/manual/en/language.operators.comparison.php
https://www.php.net/manual/en/types.comparisons.php (the "Loose comparisons with ==" table specifically)