title: How to call and view an array in a function
body: <p>I'm new to PHP and Kohana.
  I would like to know how to call an array in a function.</p>
  
  <p>I'm having the variable $productlist and I would like to add more elements into it with a function.</p>
  
  <pre><code>public $productlist =  array();
  public function action_index()
  {
     $product = new Product("Laptop","HP4897");
     $product2 = new Product("TV","Samsung 8773");
  
  
     $productlist[] = product;
     $productlist[] = product2;
  
     $this-&gt;add_product_to_array("Ebook","Everything you want to know");
     $this-&gt;show_productlist();
  }
  
  public function add_product_to_array($product_name, $product_description)
  {
      $newproduct = new Product($product_name, $product_description);
      array_push($productlist,$newproduct);
  }
  public function show_productlist(){
      foreach($productlist as $key =&gt; $value)
      {
          print_r($value-&gt;get_product_name().'&lt;/br&gt;');
      }
  }
  </code></pre>
  
  <p>and this is the exception i'm getting:
  *ErrorException [ Warning ]: array_push() expects parameter 1 to be array, null given*</p>
  
  <p>if I'm adding foreach($this->productlist as $key => $value), it tells me it can't find productlist.</p>
  
  <p>Product.php</p>
  
  <pre><code>class Product {
  
  private $_product_name;
  private $_product_description;
  
  
  function __construct($name,$description)
  {
      $this-&gt;_product_name = $name;
      $this-&gt;_product_description = $description;
  }
  
  public function get_product_name()
  {
      return  $this-&gt;_product_name;
  }
  //etc
  </code></pre>