I was thinking about adding one or two regex-related features to the engine:
1. "preg_case": this would behave just like case but instead of doing an equality comparison, would match against a regular expression, e.g.
switch($data) { preg_case '/^\d{5}(-\d{4})?$/': print "US Postal Code"; break; preg_case '/^[a-z]\d[a-z] ?\d[a-z]\d$/i'; print "Canadian Postal Code"; break; default: print "something else!"; }
i've started to play with a more general way to handle this:
switch(mixed data [, callback compare_function]) { ...
"compare_function" would default to the functionality of the "==" operator to show the current behavior
"compare_function" will be called with two parameters: the switch expression and the case value and should return true if both match, false otherwise
as a special case "compare_function" should also accept "==="
this way we do not have to add new keywords and are not limited to preg expresions here, possible uses not possible now would include:
switch($foobar, "===") { case false: ... case 0: ... case '': ...
switch($foobar, "preg_match") { case '/^\d{5}$/': ... case '/(foo)?bar/': ...
switch($foobar, "fnmatch") { case '*.gif': ... case '*.jpg': ...
switch($foober, "my_custom_function") { ...
switch($foobar, array($this, "compare_function") { ...
-- Hartmut Holzgraefe <[EMAIL PROTECTED]>
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php