title: preg_replace: reference object in replacement
body: <p>Do you know of any way to reference an object in the replacement part of preg_replace. I'm trying to replace placeholders (delimited with precentage signs) in a string with the values of attributes of an object. This will be executed in the object itself, so I tried all kinds of ways to refer to $this with the /e modifier. Something like this:</p>
  
  <pre><code>/* for instance, I'm trying to replace
   * %firstName% with $this-&gt;firstName
   * %lastName% with $this-&gt;lastName
   * etc..
   */
  $result = preg_replace( '~(%(.*?)%)~e', "${'this}-&gt;{'\\2'}", $template );
  </code></pre>
  
  <p>I can't get any variation on this theme to work. One of the messages I've been getting is: Can't convert object Model_User to string.  </p>
  
  <p>But of course, it's not my intention to convert the object represented by $this to a string... I want to grab the attribute of the object that matches the placeholder (without the percentage signs of course).</p>
  
  <p>I think I'm on the right track with the /e modifier. But not entirely sure about this either. Maybe this can be achieved much more simple?</p>
  
  <p>Any ideas about this? Thank you in advance.</p>