title: PHP Fatal error: Cannot redeclare function
body: <p>I am trying to write a logging function and so far it works. The only issue I am facing right now is that I can execute the function only one time successfully. When I call it a second time PHP states <code>PHP Fatal error:  Cannot redeclare function</code>. </p>
  
  <p>Now I wanted to ask:</p>
  
  <ol>
  <li><p>Why does PHP complain about my workflow? To my understanding I write the function placeholders3 and I can use this function again and again with different parameters. E. g. first: </p>
  
  <pre><code>$addNewCar-&gt;log(array('makeModelDescription','firstRegistration','mileage','logMessage', 'createTime'),
  array($carDetails[0]['FK_makeModelDescription'],
        $carDetails[0]['FK_firstRegistration'],
        $carDetails[0]['FK_mileage'],
        'deleteCarbyID: ' . $addNewCar-&gt;affected_rows,
        time()
  )
  </code></pre>
  
  <p>);
  and then e. g. </p>
  
  <pre><code>$addNewCar-&gt;log(array('makeModelDescription','firstRegistration','mileage','logMessage', 'createTime'),
  array($carDetails[0]['FK_makeModelDescription'],
        $carDetails[0]['FK_firstRegistration'],
        $carDetails[0]['FK_mileage'],
        'insertCarById: ' . $addNewCar-&gt;affected_rows,
        time()
  ));
  </code></pre></li>
  </ol>
  
  <p>Function logging: </p>
  
  <pre><code>    public function log($key, $values) {
      try {
  
          /** @var $tableColumns Column names in MySQL table */
          $tableColumns = $key;
  
          /** @var $tableRows Use 2-dimensional numeric or associative arrays
           * for multiple records. Single records can be added with a
           * vector */
          $tableRows[] = $values;
  
          $DBH = $this-&gt;DBH;
  
          /**
           * @param        $text       Unnamed placeholder
           * @param int    $count      Number of unnamed placeholders (size of one array)
           * @param string $separator  Separator
           *
           * @return string            Concatenated unnamed placeholders, e. g. ?, ?, ?
           */
          function placeholders3($text, $count=0, $separator=","){
              $result = array();
              if($count &gt; 0){
                  for($x=0; $x&lt;$count; $x++){
                      $result[] = $text;
                  }
              }
              return implode($separator, $result);
          }
  
          /**
           * Generate unnamed placeholders for SQL statement,
           * e. g. (?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?).
           *
           * Pitfalls:
           *
           * - Nested array:  Take care that you iterate over the items
           *                  of the nested array. E. g. $tableRows[0]
           *                  instead of $tableRows;
           *
           * - sizeof($d):    Number of elements per single array
           *                  (for a single db insert).
           */
          $insert_values = array();
          foreach($tableRows as $d){
              $question_marks[] = '('  . placeholders3('?', sizeof($d)) . ')';
              $insert_values = array_merge($insert_values, array_values($d));
          }
  
          $sql = "INSERT INTO logging (" . implode(",", $tableColumns ) . ") VALUES " . implode(',', $question_marks);
  
          $STH = $DBH-&gt;prepare($sql);
          $STH-&gt;execute($insert_values);
          $this-&gt;affected_rows = $STH-&gt;rowCount();
      }
      catch(PDOException $e) {
          error_log("PDO error: " . $e-&gt;getMessage());
      }
  }
  </code></pre>
  
  <ol start="2">
  <li>How should I change my design to get it working? </li>
  </ol>
  
  <p>Many thanks in advance!</p>