title: PHP Curly bracket variable not replaced when used as an argument in a function
body: <p>What I'm trying to do is create a reusable gallery function where the layout of the thumbnails can be changed if necessary.</p>
  
  <p>My problem is that my $thumbLayout string with curly bracket variables, doesn't work when included in the function like this, it only works when the string is written after the replacing variables.</p>
  
  <p>Would really appreciate any help with coming up with a solution or better way of doing this.</p>
  
  <pre><code>$thumbLayout = "&lt;div class=\"customgallery\"&gt;&lt;img src=\"{$thumbImgPath}\" width=\{$width}\" height=\"{$height}\" alt=\"{$imgName}\" /&gt;&lt;/div&gt;";
  
  function createImageGallery($galleryName,$db,$thumbLayout=''){
          $imgno = 1;
          //Page numbers//
          if(isset($_GET['page']) &amp;&amp; is_numeric($_GET['page'])) {
              $page = $_GET['page'];
          }elseif(isset($_POST['page']) &amp;&amp; is_numeric($_POST['page'])) {
              $page = $_POST['page'];
          }else{
              $page = 1;
          }
  
          $rowGallery = $db-&gt;query_first("SELECT gallery_id,num_cols,images_per_page FROM tblgallery WHERE gallery_name='$galleryName' AND show_gallery='y' LIMIT 1");    
          if($rowGallery!=false){
              $recordsPerPage = $rowGallery['images_per_page'];
              $numCol = $rowGallery['num_cols'];
              $gallery = '&lt;ul&gt;';
              $gallery_id = $rowGallery['gallery_id'];
  
              $offset = ($page - 1) * $recordsPerPage;
              $query = "SELECT * FROM tblimages WHERE group_id='$gallery_id' AND imgpath_thumb&lt;&gt;'' AND show_img='y' ORDER BY img_order";
                  $rs = $db-&gt;query("$query LIMIT $offset,$recordsPerPage");
                  foreach($rs as $row){
                      $largeImgPath = '/'.$row['imgpath_large'];
                      $imgName = $row['img_name'];
                      $thumbImgPath = '/'.$row['imgpath_thumb'];
                      if(($imgno&gt;1) &amp;&amp; (!is_float(($imgno-1)/$numCol))){
                          $li_class = 'class="newline"';
                      }elseif(($imgno&gt;1) &amp;&amp; (!is_float(($imgno)/$numCol))){
                          $li_class = 'class="last"'; 
                      }else{
                          $li_class = ''; 
                      }
                      list($width, $height) = getimagesize($row['imgpath_thumb']);
                      if($thumbLayout==''){
                          $gallery .= '&lt;li '.$li_class.'&gt;&lt;a href="'.$largeImgPath.'" class="popup" title="'.$imgName.'"&gt;&lt;div class="gallery_imgbox"&gt;&lt;img src="'.$thumbImgPath.'" width="'.$width.'" height="'.$height.'" alt="'.$imgName.'" /&gt;&lt;/div&gt;&lt;span&gt;'.$imgno.$imgName.'&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;';
                      }else{
                          $gallery .= '&lt;li '.$li_class.'&gt;'.$thumbLayout.'&lt;/li&gt;';
                      }
                      $imgno++;
                  }
              $gallery .= '&lt;/ul&gt;';
          }else{
              //Gallery specified does not exist//
              return 'Gallery does not exist';
          }
      return  $gallery;
  }
  </code></pre>
  
  <p>I think it is really to do with the placement of the $thumbLayout.
  When inside the function below the replacement variables it works, but when included from outside the function they don't get replaced.
  OK so here's a really simple example:</p>
  
  <pre><code>$test1 = sprintf("My name is %s.",$name);
  $test2 = "My name is {$name}.";
  $test3 = "My name is ${name}.";
  $test4 = "My name is $name .";
  $test5 = "My name is &lt;?= name ?&gt;.";
  $test6 = "My name is {{name}} .";
  
  function showtest($test){
  $name = "Bob";
  echo $test; 
  }
  
  showtest($test1); //Result: My name is .//
  showtest($test2); //Result: My name is .//
  showtest($test3); //Result: My name is .//
  showtest($test4); //Result: My name is .//
  showtest($test5); //Result: My name is .//
  showtest($test6); //Result: My name is {{name}}.//
  </code></pre>
  
  <p>Whereas this will work (but doesn't help me)</p>
  
  <pre><code>function showtest2(){
  $name = "Bob";
  $test = "My name is {$name}.";  
  echo $test; 
  }
  
  showtest2(); //Result: My name is Bob.//
  </code></pre>