RE: Re: Like ternary but without the else.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris W. Parker wrote:
> Jason Barnett <mailto:jason.barnett@xxxxxxxxxxxxx>
>     on Friday, February 25, 2005 2:10 PM said:
>
>> $this = $something ? $that : null;
>
> That won't work because I'm setting a default value for $this and want
> it to change only if it has to. The long winded way to write this would
> be:

If you *KNOW* you set the default value:

$this = $something ? $that : $this;

Crude, but effective, Captain   -- Spock

If you're not *SURE* $this has a value:

$this = ($something ? $that : (isset($this) ? $this : NULL));

Some of those parens might be un-needed, but I'd get confused without
them, never mind PHP being confused or not :-)

Course, I gotta say that maybe you're coming at this wrong in the first
place, if you have to change $this based on $something to $that but $this
already has a value...

Maybe you should have figured out what $this should be back when you first
initialized it?

Maybe not.  Can't tell without seeing more code.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux