Re: PHP 6.0 Wishlist

From: Date: Fri, 16 Sep 2005 06:49:22 +0000
Subject: Re: PHP 6.0 Wishlist
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-19029@lists.php.net to get a copy of this message
The problem with this would be that it can't be decided on a per-case basis, but only for the whole switch, which would make the execution slower. That's why I'd prefer a "regcase", but I guess this can be considered ugly becuase e.g. C(++) doesn't have a "regcase" either and it's quite a diversion from the known syntax. Ron "Hartmut Holzgraefe" <hartmut@php.net> schreef in bericht news:4329DEBE.3080204@php.net... > Ron Korving wrote: > > I have another idea I came up with today: regular expression switches, but > > it would be difficult without adding to the syntax. > > no, its actually pretty easy from a syntax point of view, > you don't need to add another keyword, just add an optional > callback parameter to switch() which is a comparison function > similar to what you pass to e.g. usort() > > that way you are not limited to one type of reges but could > have ereg or preg style or could do other things like case > insensitive switches: > > switch ($str, "ereg") { > case "[[:alpha:]]+":... > } > > switch ($str, "preg_match") { > case "/^[A-Za-z]+$/": ... > } > > switch ($str, "strcasecmp") { > ... > } > > or even > > function my_cmp($str1, $str2) { > return strcmp(str_rev($str1, $str2)); > } > > switch ($str, "my_cmp") ... > > > i have looked into implementing that quite a while ago > but hat to give up due to lack of time and understanding > at that point in time though

« previous php.internals (#19029) next »