title: Calling php method from external function produces error
body: <pre><code>function KeepSamePage($text)
   {
  $sb_w = $oPdf-&gt;GetStringWidth($text);
  
  $num_lines = explode("\n",$text);
  
  $total = 0;
  foreach($num_lines as $line)
   {
  
    $y = $oPdf-&gt;GetY();
    $page_height = 11 * 25.4;
  
    $this_width = $oPdf-&gt;GetStringWidth(strip_tags($line));
    $extra_line = floor($this_width / $w);
    $is_line = $this_width / ($w - 1);
    $is_line = $this_width == 0 ? 1 + $extra_line : ceil($is_line) + $extra_line;
    $total = $total + $is_line;
   }
  
    $sb_height = $total * 5;
    if(($page_height - $y) &lt; $sb_height){ $oPdf-&gt;AddPage(); }
  }
  
  KeepSamePage($signature_block);
  </code></pre>
  
  <p>I'm using FPDF and I'm creating a function to keep the signature page of a letter all on the same page. This checks to see if it would go to the next page and if soo, then it does an AddPage();</p>
  
  <p>The issue I'm having is that when I don't have it in a function, it works perfectly, but when I put it within a function, I get errors when calling the methods in the class represented by $oPdf.</p>
  
  <p>So, my question generally is this: Is it possible to have a regular function in PHP call a class method as I have below? If it is possible, what am I doing wrong?</p>
  
  <p>ERROR GENERATED IS: </p>
  
  <pre><code>Fatal error: Call to a member function GetStringWidth() on a non-object in /home/jarodmo/public_html/cms/attorney_signature_block.php on line 18
  </code></pre>
  
  <p>Oh, and an explanation of my function just in case you're interested or someone else finds it.</p>
  
  <p>Text has \n for new lines in it so the PDF will put the text of the signature block on the next line. Each new array element should be a new line, so I would need to multiply the number of lines by my line height, 5 in this case. (See $total * 5).  </p>
  
  <p>I check to see where we are on the page, find the difference between the page height and the Y position, then check that against the height of the signature block. If the signature block is bigger, then it wouldn't fit and I know we need a manual page break.</p>
  
  <p>Also, because I do the explode with the \n to see the lines, I also have to check to make sure that none of the lines is still wider than the page otherwise it would word wrap and really be 2 lines (or more) where I was only counting it as 1 because it was just one array element. I know a signature block shouldn't have text wide enough to be on 2 lines, but I wrote this to be applicable for more than just signature blocks. I wanted to be able to call this function anywhere I wanted to make sure certain text stayed on the same page. Call the function, check the text I'm about to write to the PDF and move on knowing that the desired text would all be on the same page.</p>
  
  <p>Thanks for all of the help and comments. SO is the best.</p>