title: PHP, Fatal error: Uncaught Error: Using $this when not in object context in
body: <p>I don't understand why this error occure.
  I want change some string in array on data from database, so i used preg_replace_callback. But when I use in definition of callback function</p>
  
  <pre><code>$row = $this-&gt;result-&gt;fetch_assoc();
  </code></pre>
  
  <p>parser replies with error</p>
  
  <p>All code:</p>
  
  <pre><code>    public function tRsql() {
          $argNums = func_num_args();
          $argsArr = func_get_args();
  
          function change($matches) {
              if(stripos($matches[0], "sql:")) {
                  $str = ltrim($matches[0], "#sql:");
                  $str = rtrim($str, ":");
                  $row = $this-&gt;result-&gt;fetch_assoc();
                  $str = $row[$str];
                  return $str;
              } else {
                  return $matches[0];
              }
          }
          for($i = 0; $i &lt; $this-&gt;numOfRows; $i++) {
              $argsArr = preg_replace_callback("/(#sql\:)\S+\:/", "change", $argsArr);
              $this-&gt;tR(implode(",",$argsArr));
          }
      }
  </code></pre>