The function I used in my post does not generate an E_NOTICE, because a
call-by-reference can be done with an unset variable (that can be set from
the function).

<?php
  error_reporting(E_ALL);

  function ifsetor(&$var, $value)
  {
    return (isset($var)) ? $var : $value;
  }

  echo ifsetor($bla, 'test');
?>

This simply prints 'test' and shows no errors. In fact, a var_dump() on $bla
will show that it's become NULL. Never mind this whole ifsetor() in
userspace issue, because it's not applicable anyway, but just for the
record, this function does not generate an E_NOTICE.

Ron


"Jasper Bryant-Greene" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Sun, 2005-10-30 at 09:52 +0100, Ron Korving wrote:
> > I'm a big fan of coalesce($param1, $param2, ..., $paramN) (or
firstset()).
> > The syntax allows for more than what ifsetor($var, $value) would do.
> > Ifsetor() could be done in userspace, but I don't see how coalesce()
could,
> > because of the variable number of parameters.
>
> It's not so much the variable number of parameters as the fact that it
> has to receive a variable that may not be set. Using a user-space
> function will cause an E_NOTICE to be thrown every time the function is
> used, because it's receiving an unset variable. It needs to be a
> language construct.
>
> FWIW, I like the $a ?? $b and $a ??= $b idea.
>
> -- 
> Jasper Bryant-Greene
> General Manager
> Album Limited
>
> e: [EMAIL PROTECTED]
> w: http://www.album.co.nz/
> b: http://jbg.name/
> p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
> a: PO Box 579, Christchurch 8015, New Zealand

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

Reply via email to