Did isset really work differently in older versions

I have legacy code that has the following:

<?PHP
    if(isset($_GET['pagina'])=="homepage") {
?>
HtmlCode1
<?php 
} else { 
?>
HtmlCode2
<?php 
} 
?>

      

I don't know exactly why, but it seems to work. Htmlcode1 is loaded when I have it? Pagina = homepage and htmlcode2 is loaded when pagina var doesn't exist or whatever (haven't actually seen anything else, just haven't). The site uses php4 (don't know the exact version). But really, how can this work? I looked at the manual and it says isset returns bool ..

Anyone?

0


source to share


4 answers


The problem is that "==" is not type-sensitive. Any (non-empty) string "equals" but is not identical to boolean true (you need to use the "===" operator for this).

A quick example of why you are seeing this behavior:
http://codepad.org/aNh1ahu8



And more details on this can be found in the documentation:
http://php.net/manual/en/language.operators.comparison.php
http://ca3.php.net/manual/en/types.comparisons.php ("Free comparisons with = =" on purpose)

+3


source


isset()

returns true or false. In a boolean comparison, "homepage"

will evaluate to true

. Essentially, you ended up here:

if ( isset($_GET['pagina']) == true )

      



If pagina is equal to anything, you will see HtmlCode1. If it is not installed, you will see HtmlCode2.

I just tried it to confirm it, and going to ?pagina=somethingelse

, do not show HtmlCode2.

+7


source


I suspect this is a bug since there really is no point in comparing true / false to "home page". I would expect that the code should really be:

if (isset($_GET['pagina']) && ($_GET['pagina'] == "homepage")) {
}

      

+4


source


Some ideas how this might work (apart from the previously mentioned "home page" == true):

  • Is the network redefined somewhere?
  • Is this a self-modified version of PHP?
0


source







All Articles