Reply to Re: short if else

Your name:

Reply:


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>

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация