title: Pass PHP Class as Parameter
body: <p>How can i pass a class as a parameter in my function</p>
  
  <p>So far i've tried</p>
  
  <blockquote>
  <pre><code>$sc = new SampleClass();
  SampleFunction($sc);
  
  
  function SampleFunction(&amp;$refClass)
  {
      echo $refClass-&gt;getValue();
  }
  </code></pre>
  </blockquote>
  
  <p>this is a simplified example of what im doing.. i actually have to do complex procedures inside this sample function. I'm not getting any response from the sample function. What am i doing wrong? thank you</p>
  
  <p><strong>UPDATE</strong></p>
  
  <blockquote>
    <p>char.php</p>
  </blockquote>
  
  <pre><code>   class Charss {
      var $name=0;
      var $hp=500;
      var $spd=10;
      var $rtime=10;
      var $dmg=10;
  
      function __construct( $name, $hp, $spd, $rtime , $dmg) { 
              $this-&gt;name = $name;
              $this-&gt;hp = $hp;
              $this-&gt;spd  = $spd;
              $this-&gt;rtime = $rtime;
              $this-&gt;dmg = $dmg;
          }
  
      function get_name() {
          return $this-&gt;name;
      }
  
      function set_name($new_name) {
          $this-&gt;name = $new_name;
      }
  
      function get_hp() {
          return $this-&gt;hp;
      }
  
      function set_hp($new_hp) {
          $this-&gt;hp = $new_hp;
      }
  
      function get_spd() {
          return $this-&gt;spd;
      }
  
      function set_spd($new_spd) {
          $this-&gt;spd = $new_spd;
      }
  
      function get_rtime() {
          return $this-&gt;rtime;
      }
  
      function set_rtime($new_rtime) {
          $this-&gt;rtime = $new_rtime;
      }
  
      function get_dmg() {
          return $this-&gt;get_dmg;
      }
  
      function set_dmg($new_dmg) {
          $this-&gt;dmg = $new_dmg;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>myclass.php</p>
  </blockquote>
  
  <pre><code>    require("char.php");
  class Person {
  
  function try_process()
  {
      $chr1 = new Charss("Player1",500,3,0,50);
      $chr2 = new Charss("Player2",500,6,0,70);
  
      while ($chr1-&gt;get_hp() &gt; 0 &amp;&amp; $chr2-&gt;get_hp() &gt; 0)
      {
          $sth = min($chr1-&gt;get_rtime(), $chr2-&gt;get_rtime());
          if ($chr1-&gt;get_rtime() == 0 &amp;&amp; $chr2-&gt;get_rtime() &gt; 0)
          {
              exit;
              Fight($chr1,$chr2);
              $chr1-&gt;set_rtime($chr1-&gt;get_spd());
          }
          elseif ($chr2-&gt;get_rtime() == 0 &amp;&amp; $chr1-&gt;get_rtime() &gt; 0)
          {
              Fight($chr2,$chr1);
              $chr2-&gt;set_rtime($chr2-&gt;get_spd());
          }
          else 
          {
              Fight($chr1,$chr2); #having trouble with this
              $chr1-&gt;set_rtime($chr1-&gt;get_spd());
          }
          $chr1-&gt;set_rtime($chr1-&gt;get_rtime() - $sth);
          $chr2-&gt;set_rtime($chr2-&gt;get_rtime() - $sth);
      }
  }
  
  function Fight($atk,$def)
  {
      $def-&gt;set_hp($def-&gt;get_hp() - $atk-&gt;get_dmg());
      echo $atk-&gt;get_name() . " attacked " . $def-&gt;get_name() . " for " . $atk-&gt;get_dmg() . " damage";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>so im calling the function try_process on button click</p>