Re: Parameter passing question [message #173569 is a reply to message #173545] |
Tue, 19 April 2011 03:28 |
Curtis Dyer
Messages: 34 Registered: January 2011
Karma:
|
Member |
|
|
Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> wrote:
> Unrest wrote:
>
>> Am Mon, 18 Apr 2011 17:42:31 +0000 schrieb Denis McMahon:
>>> <?php
>>> if (isset($_GET['x'])) {
>>> if ($_GET['x'] == null) {
>>> // it's null
>>> } else {
>>> // it has data
>>> }
>>> } else {
>>> // it's not defined
>>> }
>>> ?>
>>>
>>
>> isset() checks if a variable exists and _is not null_.
Right.
>> -> http://de.php.net/manual/en/function.isset.php
>>
>> so your "if ($_GET['x'] == null)" will never evaluate to true.
>
> True.
Not quite, because, as far as I can tell, PHP will treat query
string parameters without values as empty strings within the
superglobals. Note that that the "==" operator doesn't perform
strict type checking, so a comparison with NULL will yield true
when compared with an empty string.
> if (array_key_exists('x', $_GET))
> {
> if ($_GET['x'] == null)
Here, using ``empty()'' may be clearer.
> {
> // ...
> }
> }
>
> would make sense then.
This approach is still a bit nicer, IMO. It more clearly shows
the intent of the author and is more versatile when handling
arrays in which the values can actually be NULL.
--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
|
|
|