title: Passing arrays of varying size to setters/functions in Php
body: <p>I am relatively new to PHP and have searched quite extensively but can't quite figure out the solution to my problem.</p>
  
  <p>I am trying to figure out how to use setters in a class where the variable being set is an array of an unknown size. For example:</p>
  
  <pre><code>class Shirt 
  {   
      private $sizes=array();
  
      public function setSizes($x) 
      {
          $this-&gt;sizes=array($x);
      }
  
  }
  
  $BlueShirt = new Shirt;
  $BlueShirt -&gt; setSizes (12,14,16);
  </code></pre>
  
  <p>The above code will only set the first size declared in the $BlueShirt object. In some cases shirt objects will have 3 sizes, others may have 3 or 4 and again others may have only 1. I know a simple solution would be to declare the array() in the object:</p>
  
  <pre><code>class Shirt 
  {      
      private $shirts;
  
      public function setShirt($x); 
      {
          $this-&gt;shirts=($x);
      }
  }
  
  $BlueShirt = new Shirt;
  $BlueShirt -&gt; setShirt(array(12,14,16));
  </code></pre>
  
  <p>However, I really prefer not to go that route. I use this initial size data in other functions that return size ranges, etc. These functions require that the size data be in array form. I would much rather force the array as even with clear commenting, it may not be obvious to future users adding objects that objects with only one size should still be entered as an array.</p>
  
  <p>Thanks for any help in advance.</p>