|
Posted by Kimmo Laine on 12/28/05 21:53
"Mladen Gogala" <gogala@sbcglobal.net> kirjoitti
viestissδ:pan.2005.12.28.16.33.43.195144@sbcglobal.net...
> On Wed, 28 Dec 2005 11:51:29 +0100, Moneypenny wrote:
>
>> All gives a parse error.
>>
>> How can i do this?
>>
>> Tnx.
>
> Well, everything else aside, there is a trick you can use:
>
> $ cat /tmp/ttt
> #!/usr/local/bin/php
> <?php
> $test=1;
> $test == 1 ? eval('$do = true; $who = "me";') : $do = false;
> echo "Do: $do Who:$who\n";
> ?>
>
> $ php /tmp/ttt
> Do: 1 Who:me
> $
>
Yep, this is the one I was thinking. But NO. Let me say that just one more
time, NOOOO! As I said this would be very bad coding practise, since there
is no reason to use eval to write a shorthand if-else. It's just stupid. How
I wish you hadn't brought it up. And yet you did... It is said that if you
need to use eval, you're not doing it right. Using eval and the ternary
operator instead of if and else is not the choice of a sane person.
--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <antaatulla.sikanautaa@gmail.com.NOSPAM.invalid>
Navigation:
[Reply to this message]
|