You are here: Re: Macros in php « PHP Programming Language « IT news, forums, messages
Re: Macros in php

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация