title: PHP dynamic string update with reference
body: <p>Is there any way to do this:</p>
  
  <pre><code>$myVar = 2;
  $str = "I'm number:".$myVar;
  $myVar = 3;
  
  echo $str;
  </code></pre>
  
  <p>output would be: <code>"I'm number: 3";</code></p>
  
  <p>I'd like to have a string where part of it would be like a pointer and its value would be set by the last modification to the referenced variable.</p>
  
  <p>For instance even if I do this:</p>
  
  <pre><code> $myStr = "hi";
   $myStrReference = &amp;$myStr;
   $dynamicStr = "bye ".$myStrReference;
   $myStr = "bye";
   echo $dynamicStr;
  </code></pre>
  
  <p>This will output "<code>bye hi</code>" but I'd like it to be "<code>bye bye</code>" due to the last change. I think the issue  is when concatenating a pointer to a string the the pointer's value is the one used. As such, It's not possible to output the string using the value set after the concatenation.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>Update</strong>: the <code>$dynamicStr</code> will be appended to a <code>$biggerString</code> and at the end the <code>$finalResult</code> (<code>$biggerString+$dynamicStr</code>) will be echo to the user. Thus, my only option would be doing some kind of <code>echo eval($finalResult)</code> where <code>$finalResult</code> would have an <code>echo($dynamicStr)</code> inside and <code>$dynamicStr='$myStr'</code> (as suggested by Lawson), right?</p>
  
  <p>Update:</p>
  
  <pre><code>$myVar = 2;
  $str = function() use (&amp;$myVar) {
      return "I'm number $myVar";
  };
  
  $finalStr = "hi ".$str();
  $myVar = 3;
  echo $finalStr; 
  </code></pre>
  
  <p>I'd like for this to ouput: "hi I'm number 3" instead of "hi I'm number 2"...but it doesn't.</p>