Re: Seemingly weird regex problem

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

 



Tim Boring wrote:
> It's perfectly legit to use expressions.  Now perhaps there is something
> wrong with the regex I'm trying to use, but using a regex in and of
> itself is legal.
> http://www.php.net/manual/en/control-structures.switch.php

Ah...

Well, the User Contributed notes provide some examples, and the manual
says you can use expressions, but nothing clarifies, for me, the
interaction betwee n $x and [expression] in:

switch ($x){
  case [expression]: /* code */; break;
}

Is $x compared to the return value of [expression]?

I think what you need, then, is TRUE instead of $x.

...  I think I'll go out on a limb and say that in MOST CASES it would be
Bad Style to have both $x and [expression]...  I mean, it just gets too
confusing.

And if you expressions also have side-effects (incrementing, for example)
then it would be REALLY UGLY to do, like:

switch ($x){
  case ($x++): /* code */ break;
  case ($x): /* code */ break;
}

[shudder]

I pity the programmer that has to make sense of something as messy as that.

Maybe I'm just "missing" a really elegant example of how cool this would
be, but it seems rife for confusion to me.

-- 
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