[UPHPU] Re: short syntax without the else?

D. Turnbull turnbud at gmail.com
Sun Jan 20 13:46:53 MST 2008


If it's important to use the ternary operator, you can accomplish what
you want like this:

$var = condition ? this : $var;

While the end result is the same, this is not quite the same as

    if(condition) { $var = this;}

because in the ternary version, $var is assigned a new value either
way (although if the condition is false, it is re-assigned the same
value) -- but in the "if" version, $var is only acted on when
condition is true.

Regards,

Dave

>
> Can you do this syntax…
>
>         $var = condition ? this : that;
>
>
> …without the that? Like this…
>
>         $var = condition ? this;
>
>
> …? If yes, would it be the same as…
>
>         if(condition) {
>                 $var = this;
>         }



More information about the UPHPU mailing list