No, you don't need to initialize $matches. It's passed by reference and thus
doesn't need to be initialized.
And as I already said: It is good practice to ensure that preg_match
actually matched something:

if (preg_match(REGEX, $string, $matches)) {
    // in here $matches is guaranteed to be defined
}

If you don't do that you will work with $matches even though there was no
match - which is pointless and
will probably result in bugs.

On Fri, Jul 8, 2011 at 3:18 PM, Rafael Dohms <lis...@rafaeldohms.com.br>wrote:

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

Reply via email to