Re: isset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Afan Pasalic wrote:
>>
>> Jochem Maas wrote:
>>> Richard Kurth wrote:
>>>
>>>> What do you do when isset does not work? If I send data in a
>>>> $_REQUEST['var'] like
>>>> if (isset($_REQUEST['var'])) {
>>>> }
>>>> Put var has no data it still says it is set. Because $_REQUEST['var']
>>>> = ""
>>>> and isset thinks "" is set
>>>>
>>>
>>> php -r ' $r = array("foo" => "");
>>> var_dump(isset($r["foo"]),empty($r["foo"]));'
>>>
>>> so empty() should give you the result your looking for  ...
>>> some tips:
>>>
>>> 1. generally use $_GET or $_POST in preference to $_REQUEST
>>> 2. be specific about your input validation, e.g.:
>>>
>>> if (isset($_GET['var']) && ($_GET['var'] == 'foo')) {
>>> 	echo "got it!";
>>> }
>>>
>> I always wondered about this. if $_GET['var'] == 'foo' is true, isn't
>> automatically isset($_GET['var']) true too?
>> I mean, isn't
>> if ($_GET['var'] == 'foo')
>> {
>>     echo "got it!";
>> }
>> just enough?
>
> it doesn't cover the situation where $_GET['var'] doesn't exist,
> and using uninitialized var is not recommended.
>
> of course it's your call whether you write/run code that spits out
> E_NOTICEs all over the place due to usage of uninitialized vars.
>

not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not equal to
'foo', right?

how I understand:
clause one: isset($_GET['var'])
clause two: ($_GET['var'] == 'foo')
if clause two is true, clause one MUST be true.
if clause one is true, clause two could be true or false.

means, if I look for solutions where ($_GET['var'] == 'foo') they wil
lautomaticaly cover isset($_GET['var']) part.
if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or
!isset($_GET['var']).

or I'm missing something here?

I have E_NOTICE turned off. :)

thanks.

-afan

>>
>> -afan
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux