FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » switch with case 0
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: switch with case 0 [message #182632 is a reply to message #182630] Mon, 19 August 2013 17:39 Go to previous messageGo to previous message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma:
Senior Member
Thomas 'PointedEars' Lahn schrieb:

> But PHP, after all, also allows for strict comparison to avoid this problem.

True, there are === and !==. Unfortunately, though, there are no
"strict" equivalents for <, <=, > and >=. That would be nice to have.

> BTW, because of discussions like this one, switch-case has been either
> removed in an early version from or is never going to be introduced into
> Python,

I think the original reason for switch was to evaluate the expression
only once and use the result as an offset in a "jump table". And
actually, the Pythonic equivalent of switch is not an if-elif-else
structure, but a dict of functions.

> and that is precisely what you should do in PHP if the type matters:
>
> if ($foo === 1)
> {
> // …
> }
> else if ($foo === 2)
> {
> // …
> }
> else if ($foo === 3)
> {
> // …
> }
> else
> {
> /* default */
> }

Indeed, you're right.

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: AND and OR
Next Topic: Compiling PHP 5.x on Cygwin
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 11:53:32 GMT 2024

Total time taken to generate the page: 0.04407 seconds