Search code examples
phpissetsuperglobals

PHP 5.4-specific ISSET query regarding $_GET. $_POST Superglobals


I have to upgrade a mission-critical (aren't they all?) Ubuntu server from PHP 5.3 to 5.4, and am happy about all but 1 possible problem. Our PHP scripts include around 1200 ISSET() references, nearly all of which check the status of either $_GET or $_POST variables, whose names all comprise strings, not numerics.

I'm aware of the (5.3 v 5.4) distinction where 5.4 returns false when ISSET($var['somestringvalue']) is used, and my query is whether this unwanted behaviour will apply to our string-value $_POST and $_GET variables?

I would knock up a quick 5.4 test server, but we use so many extensions and adjustments that even that's easier said than done. so I thought I'd try my luck here first. Thanks in advance.


Solution

  • That is not an "unwanted behaviour", it's actually useful. The behaviour only changes if isset() is called on a string.

    $string = 'My string'; // length = 9, character indexes 0 to 8
    var_dump(isset($string[5])); // makes sense -> checks whether there's a character on the 5th position (true)
    var_dump(isset($string[10])); // makes sense -> checks whether there's a character on the 10th position (false)
    var_dump(isset($string['foo'])); // doesn't make sense -> checks whether there's a character on the "foo" position (false)
    

    Since $_GET and $_POST are always associative arrays, this new behaviour will not affect you in any case. For more information, check the manual at http://php.net/manual/en/function.isset.php

    PS: you should consider a development server, to test things like this without creating problems for your users / customers!