Hi,
usage of references here have some bad consequences, it will pollute
the input array with null entries:

function foo(&$a) { }
var_dump(array_key_exists('inexistent', $_GET)); // bool(false)
foo($_GET['inexistent']);
var_dump(array_key_exists('inexistent', $_GET)); // bool(true)

will actually create the inexistent entry and fill it with null.
Again, there is no perfect implementation of an issetor in userland.

On Jan 26, 2008 6:22 PM, Sam Barrow <[EMAIL PROTECTED]> wrote:
> I'm sorry I misunderstood. If specifying like "$var ?: 5" then it should
> throw an E_NOTICE, as this is a conditional that checks the value of a
> variable ($var).
>
> Sebastian, for assigning of a default value is a variable is not set, I
> would recommend using something like this (this is what I use):
>
> function ifsetor(&$var, $or) {
>         return isset($var) ? $var : $or ;
> }
>
> Because $var is passed by reference, it won't throw an E_NOTICE when
> passing an undeclared variable.
>
> On Sat, 2008-01-26 at 17:30 +0100, Sebastian wrote:
>
> > hi,
> >
> > i just found the new ifsetor like construction in php6. It left me the
> > question why php has to throw an E_NOTICE when the variable is not set. This
> > is basicly because that actually is the meaning of this construction,
> > checking if the variable is set and if it isnt give back a standard value.
> > Of course i know this construction can be (mis)used with an Boolean check
> > ($var===$var2), but this does not make much sence either because TRUE will
> > then be assigned to the new variable if the expression evaluates to TRUE
> > (but please correct me if theres a real use for this).
> >
> > So in any case it would be better to remove the Boolean check feature and
> > make it a simple ifsetor() without the E_NOTICE again.
> >
> > For those of you who have not heard of it heres an example:
> >
> > <?php
> >
> > // If $_GET['foo'] is set, then its value will be assigned to $foo,
> > // otherwise 42 will be assigned to $foo.
> >
> > $foo = $_GET['foo'] ?: 42;
> >
> > ?>
> >
> > Greetings
> >
> > Sebastian
> >
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>



-- 
Etienne Kneuss
http://www.colder.ch

Men never do evil so completely and cheerfully as
when they do it from a religious conviction.
-- Pascal

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to