Fix use of preg_match_all in MagicWord.php
authorumherirrender <umherirrender_de.wp@web.de>
Thu, 10 Sep 2015 19:43:46 +0000 (21:43 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Thu, 10 Sep 2015 19:43:46 +0000 (21:43 +0200)
Init variable before use
Check return value to avoid notice on failures

Change-Id: I5cecae32f7672d748706c7a72bf01e9aee65e6d4

includes/MagicWord.php

index 833f852..2c7ba91 100644 (file)
@@ -950,10 +950,12 @@ class MagicWordArray {
                        if ( $regex === '' ) {
                                continue;
                        }
                        if ( $regex === '' ) {
                                continue;
                        }
-                       preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
-                       foreach ( $matches as $m ) {
-                               list( $name, $param ) = $this->parseMatch( $m );
-                               $found[$name] = $param;
+                       $matches = array();
+                       if ( preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ) ) {
+                               foreach ( $matches as $m ) {
+                                       list( $name, $param ) = $this->parseMatch( $m );
+                                       $found[$name] = $param;
+                               }
                        }
                        $text = preg_replace( $regex, '', $text );
                }
                        }
                        $text = preg_replace( $regex, '', $text );
                }