diff --git a/mod/data/edit.php b/mod/data/edit.php
index <HASH>..<HASH> 100644
--- a/mod/data/edit.php
+++ b/mod/data/edit.php
@@ -295,6 +295,8 @@ if (!$rid){
  ******************************************/
 if ($data->addtemplate){
     $possiblefields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id');
+    $patterns = array();
+    $replacements = array();
 
     ///then we generate strings to replace
     foreach ($possiblefields as $eachfield){
MDL-<I> data: Init 2 arrays (global scope) that may conflict with other global scope code