Re: Seemingly weird regex problem

From: Date: Thu, 20 Jan 2005 19:49:02 +0000
Subject: Re: Seemingly weird regex problem
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-206876@lists.php.net to get a copy of this message
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

« previous php.general (#206876) next »