title: PHP Recursive function gone wrong, recursion within a do while
body: <p>I did all sorts of debugging and referred to a multitude of sources and can't figure this out on my own.
  I just started working with OOP in PHP and I'm trying to write a poker hand dealer. I attempt to use a recursive function and a loop and and an if else algorithm to avoid creating duplicates in the pokerHand array. My idea of how this code should work is that when a new pokerHand object is created the __construct function will be automatically called (that's the only reason i know of to use a constructor, but i think there's more to it). Then within a do while loop the code initializes a variable $rand which is a rand number between 1 &amp; 52 and in_array checks to see if that "card" has already been entered in the array. If the card has been dealt the __construct function is supposed to call itself to produce another card until a novel card has been dealt before storing it in the array. </p>
  
  <p>I am just starting out as a coder and any feedback on my code here will be of immeasurable value to me and I thank you in advance. </p>
  
  <pre><code>&lt;?php
   class pokerHand {
      private $_pokerHand = array();
      private $_counter = 0;
  
  
      public function __construct (){
  
          do{
  
              if  (in_array ($rand = rand(1,52), $this-&gt;_pokerHand) ){
                  return public function __construct();
              } else {
                  $this-&gt;_pokerHand[] = $rand;
                  $this-&gt;counter++;    
              }
          } while ($this-&gt;_counter &lt; 5)
  
  
      public function showHand(){
          print_r ($this-&gt;_pokerHand);
      } 
  
   }
  
  
  
  
  $obj = new pokerHand();
  $obj =&gt; showHand();
  ?&gt;
  </code></pre>