On Wed, Apr 20, 2011 at 5:12 PM, Alain Williams <a...@phcomp.co.uk> wrote:

> On Wed, Apr 20, 2011 at 04:55:00PM +0200, Mark wrote:
> > Hi,
> >
> > This proposal is for the often called line like this:
> > $var = isset($_GET['var']) ? $_GET['var'] : '';
> >
> > Only a shorter and imho a cleaner solution to get the same:
> > $var = varset($_GET['var']);
>
> It should be called var_set() - better on name space pollution.
>

oke


>  > However there is a slight issue with this approach. If notices are
> turned on
> > this code will generate a notice while i think it should not do that. But
> > perhaps this approach is "to short".
> > A slightly different implementation (and longer) prevents the notice:
>
> If is is a language element (like isset()) then you can avoid this problem.
>

Could you explain that a bit more?


> I do find a lot of code, in simple scripts, that does just that.
>
> It might be nice to extend it such that if the 1st argument is a list then
> the
> first in the list which is set is returned, eg:
>
>        $var = var_set(($_GET['var'], $_POST['var']), 'default');
>
>
I might be missing the point here, but the way i understand it that can give
unexpected results.. since it returns the first element from an array in
your suggestion but that's not what you want to do.


> --
> Alain Williams
> Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT
> Lecturer.
> +44 (0) 787 668 0256  http://www.phcomp.co.uk/
> Parliament Hill Computers Ltd. Registration Information:
> http://www.phcomp.co.uk/contact.php
> #include <std_disclaimer.h>
>

Reply via email to