有没有办法在不先声明变量的情况下使用preg_match_all?

Is there some fancy syntax I can use within the preg_match_all function to establish the new $matches variable at that time, rather than doing so beforehand as I have done below?

 $matches = '';
 preg_match_all('/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/', file_get_contents($eFetchURL), $matches);

Thanks in advance for your help!

Yes, namely this:

preg_match_all('/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/', file_get_contents($eFetchURL), $matches);

Taking the reference of a non-existent variable in PHP is not an error. Rather, PHP automatically declares the variable for you and defines it as NULL.

Not declare variables throws an E_NOTICE. Depending on the php.ini or runtime configuration, using error_reporting function, exception may be omitted or not.

Good practice is to have E_STRICT mode enabled in development environment.

Note:

Enabling E_NOTICE during development has some benefits. For debugging purposes: NOTICE messages will warn you about possible bugs in your code. For example, use of unassigned values is warned. It is extremely useful to find typos and to save time for debugging. NOTICE messages will warn you about bad style. For example, $arr[item] is better to be written as $arr['item'] since PHP tries to treat "item" as constant. If it is not a constant, PHP assumes it is a string index for the array.

Note:

In PHP 5 a new error level E_STRICT is available. As E_STRICT is not included within E_ALL you have to explicitly enable this kind of error level. Enabling E_STRICT during development has some benefits. STRICT messages will help you to use the latest and greatest suggested method of coding, for example warn you about using deprecated functions.

You can find more information in

http://php.net/manual/en/errorfunc.configuration.php