title: preg_replace which uses the return value of function as replacement
body: <p>I have the following code:</p>
  
  <pre><code>$message = preg_replace($pattern, "$this-&gt;get_bitly_url('$0')", $message);
  
  function get_bitly_url($url) {
      // do stuff to get the url
  
      return $newurl;
  }
  </code></pre>
  
  <p>I would like to replace the matches with the return value of the function <code>get_bitly_url()</code> in the same class.</p>
  
  <p>But I got the following error:</p>
  
  <pre><code>Notice: Undefined property: MyClass::$get_bitly_url in /path/to/MyClass.php on line 43
  </code></pre>
  
  <p>So I changed to preg_replace with:</p>
  
  <pre><code>$message = preg_replace($pattern, "self::get_bitly_url('$0')", $message);
  </code></pre>
  
  <p>This works, but I would like to know whether this is the right way to do it.</p>
  
  <p>So... is it?</p>