RE: [PHP] Re: Like ternary but without the else.
| From: | Richard Lynch | Date: | Tue, 01 Mar 2005 01:12:15 +0000 |
| Subject: | RE: [PHP] Re: Like ternary but without the else. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-209656@lists.php.net to get a copy of this message | ||
Chris W. Parker wrote:
> Jason Barnett <mailto:jason.barnett@telesuite.com>
> 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