On Fri, Jul 8, 2011 at 9:20 AM, Nikita Popov <nikita....@googlemail.com> wrote:
> 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.

That is just one use case as i see it its very cluncky to use this in
case you want to extract matches, you need to initilize the $matches
variable beforehad or you get a notice, so a simple extract is now 3
lines of code.

Thus, that is the reason why i suggest a new preg_extract function
that would handle the other use cases in a optimized way.

-- 
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

Reply via email to