The most common use for preg_match is validation: if (!preg_match('~...~', $string)) { /* do something */ }
Here $matches is not required, only the 0/1 return value of preg_match is of interest. Furthermore, even if you need $matches, you should always combine it with an if: if (!preg_match('~...~', $string, $matches)) { /* do something with $matches */ } Otherwise you will access $matches even though the match failed (which will result in errors). Thus: There is no need to change behavior here. On Fri, Jul 8, 2011 at 2:12 PM, Rafael Dohms <lis...@rafaeldohms.com.br>wrote: > I was wondering if anyone ever thought of either fixing or writing a > new function that would make preg_match actually work in a way that > made sense? > > right now i need to pass in a optional parameter that will receive the > match, in this case one or no match, why should this not be the > function's return already? > > something like: > > $string = "<td>my text</td>"; > $result = preg_match("/\<td\>(.*)\<\/td\>/", $string); > > $result // = "my text" > > Maybe something like preg_extract? I do not have the C skills to write > a patch but i think adding a new function would not break BC or have > negative side effects, would it? > > -- > Rafael Dohms > PHP Evangelist and Community Leader > http://www.rafaeldohms.com.br > http://www.phpsp.org.br > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >