David Sklar wrote:
One thing that I suppose you get by using "case preg_match()" like George
does below (as opposed to my preg_case operator or Hartmut's callback) is
you can deal with arbitrary arguments to the preg_match() (or other)
function -- storing captured subpatterns from the regex, for example.



Aesthetics aside, how is that different in effect from:

switch(true) {
  case preg_match('/foo.*?bar/i', $data):
     /** stuff **/
     break;
  case preg_match('/baz/', $data);
     /** other stuff **/
     break;
   default:
      break;
}

the "switch(true)" trick is completely ugly IMHO and is just an obfuscated way to write an if-elseif-...-else chain

my point of view is that you use switch whenever you have a
series of tests against a single value whereas in the code
snippet above you could also test against e.g. $date instead
of $data in some of the cases
whereas this is meant to be so or a typo does not become clear

by extending the switch statement itself in the way i propoesd
you gain extra functionality from switch while keeping the
"tests against a single value" contract

i was originaly just thinking about an optional flag that
would switch to "===" behaviour instead of just "==" but
the callback mechanism was just too obvious :)

and if you need extra parameters you can always wrap up
whatever test function you use in an extra wrapper function ;)



--
Hartmut Holzgraefe  <[EMAIL PROTECTED]>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to