title: PHP unserialize array
body: <p>So I am dealing with customer shopping basket. The best way I found suitable for my purpose was to store objects (with setting properties for each item attribute) in an array. So I ended up with an array of objects ItemObject type. </p>
  
  <p><br>
  I read the best way to store this array of objects in MySQL table, was to serialize it hence converting it to string and then storing it. Then when I need it I can unserialize() it with the php function. <br></p>
  
  <p>I did just that...and now that I unserialize it, I get an error....the code follows for the ItemObject, and the unserialization part. How can I unserialize that string back to array of objects of type ItemObjects so that I could iterate and print out the details of each item?</p>
  
  <pre><code>&lt;?php
  $dateSelected = $_GET['date'];
  echo "Date: ".$dateSelected . "&lt;br&gt;";
  mysql_connect();
  mysql_select_db("dashjkd");
  $result = mysql_query("SELECT order_object FROM orders WHERE orderDate = '".$dateSelected."'");
  if(mysql_num_rows($result) &gt; 0){
      $temp;
      while($row = mysql_fetch_assoc($result)){
          $temp = $row['order_object'];
          //print_r($temp);
      }
      echo "Array: &lt;br&gt;";
  
      $basketObjArray = array();
      $basketObjArray = unserialize($temp);
      print_r($basketObjArray);
      foreach($basketObjArray as $key =&gt; $value)
      {
          echo "Key: " . $key;
          echo "Value: ". $value;
      }
  
  }else{
      echo "Something went horribly wrong..try again!";
  }
  ?&gt;
  </code></pre>
  
  <p>And this unserilization code leads to this error and strange output:</p>
  
  <pre><code>Date: 2012-04-18
  Array:
  Array ( [0] =&gt; __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] =&gt; ItemObject [itemNameVar] =&gt; whitethoab [itemQtyVar] =&gt; 12 [itemPriceVar] =&gt; 10 ) [1] =&gt; stdClass Object ( [itemNameVar] =&gt; woolthoab [itemPriceVar] =&gt; 10 [itemQtyVar] =&gt; 2 ) [2] =&gt; stdClass Object ( [itemNameVar] =&gt; shemag [itemPriceVar] =&gt; 4 [itemQtyVar] =&gt; 1 ) [3] =&gt; stdClass Object ( [itemNameVar] =&gt; jacket [itemPriceVar] =&gt; 12 [itemQtyVar] =&gt; 2 ) ) Key: 0
  Catchable fatal error: Object of class __PHP_Incomplete_Class could not be converted to string in /home/sdsds/public_html/laundry/customerorder.php on line 21
  </code></pre>
  
  <p>the itemObject I designed was very simple and worked before when I attempted to display the array before serializing it:</p>
  
  <pre><code>class ItemObject{
                              public $itemNameVar;
                              public $itemQtyVar;
                              public $itemPriceVar;
  
                          }
  </code></pre>
  
  <p>Thanks for the help :)</p>