php preg_replace_all我需要定义$ matches吗?

I typically call preg_match_all using $pattern, $subject, $matches, like

preg_match_all("/\S/","words",$matches);

However, my IDE (Netbeans) is yelling at me because $matches (which is passed by reference and will be assigned the result of preg_match_all) is undefined so it doesn't want me to pass it as a parameter. Its happy with something like:

$matches=[];
preg_match_all("/\S/","words",$matches);

However, this seems superfluous, and the examples on php.net do not define the variable ahead of time. What is the "proper" way to do this? Can I just ignore Netbeans?

Ignore NetBeans. As you say, the PHP manual doesn't define the variable, and I've tested it with all error reporting on and no notice error is given.

Also, the IDE I use, PHPStorm, doesn't show an undefined error for the $matches variable.

You may safely ignore Netbeans, or you may configure Netbeans to complain less.

It may be considered good style to declare your variables before use, even when those variables are output-only. PHP doesn't care: PHP will overwrite whatever $matches is before hand even if it doesn't exist:

$matches = new StdClass();
$ok = preg_match_all('/foo/', "foo bar", $matches);
var_dump($ok, $matches);

Whether that's a good, or a bad, thing is user-defined. :)

Finally, you may consider a helper function which will both quiesce Netbeans and reduce your typing:

function get_matches($pattern, $subject, $options = null) {
    $matches = array ();
    preg_match_all($pattern, $subject, $matches, $options);
    return $matches;
}