|
Posted by Tim Martin on 11/18/56 11:44
Emil wrote:
> Kimmo Laine napisał(a):
>
>>> $var = isset($_POST['postvar']) ? $_POST['postvar'] . 'default value';
>>>
>
> I have the same problem.
>
>>
>> And tell mme again why you couldn't write a function instead of a
>> macro to do that?
>
> The reason is when you pass $_POST['postvar'] to a function and
> $_POST['postvar'] is not set, PHP generates warning. Of course one could
> turn off warnings and usually does, but in my opinion it's not a
> solution.
Surely $_POST is a superglobal and will thus be available within the
function scope just as it would be within the macro "scope".
Couldn't you do something like this (untested code, function name is
deliberately bad)?
function get_post_var_with_default($name, $default = 'default value')
{
if (isset($_POST[$name]))
{
return $_POST[$name];
}
else
{
return $default;
}
}
then later
$var = get_post_var_with_default('postvar');
Am I missing something here?
Tim
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Navigation:
[Reply to this message]
|