title: How to convert this PHP array of objects to json?
body: <p>I have an array of 10 objects that I am trying to convert to JSON.  The array is being stored in a variable called <code>$invoices</code>.  Below is the ouput of <code>var_dump($invoices)</code> shorted to only the first object.</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>$invoices = json_encode($invoices, FALSE);
  $invoices = json_encode($invoices, TRUE);
  $invoices = json_encode($invoices, JSON_UNESCAPED_UNICODE);
  </code></pre>
  
  <p>However, the output is always:</p>
  
  <pre><code>string(31) "[{},{},{},{},{},{},{},{},{},{}]"
  </code></pre>
  
  <p>How can this array be properly converted to JSON?</p>
  
  <p>Note:  I am running PHP 5.5.9</p>
  
  <p>Update:</p>
  
  <p>It turns out the problem is due the fact that json_encode won't work with "protected member variables."  Is there a way to declare those variables as public if I don't have access to the class that created them?</p>
  
  <pre><code>array(10) {
    [0]=&gt;
    object(QuickBooks_IPP_Object_Invoice)#285 (1) {
      ["_data":protected]=&gt;
      array(22) {
        ["Id"]=&gt;
        array(1) {
          [0]=&gt;
          string(6) "{-224}"
        }
        ["SyncToken"]=&gt;
        array(1) {
          [0]=&gt;
          string(1) "0"
        }
        ["MetaData"]=&gt;
        array(1) {
          [0]=&gt;
          object(QuickBooks_IPP_Object_MetaData)#282 (1) {
            ["_data":protected]=&gt;
            array(2) {
              ["CreateTime"]=&gt;
              array(1) {
                [0]=&gt;
                string(25) "2014-12-07T09:48:47-08:00"
              }
              ["LastUpdatedTime"]=&gt;
              array(1) {
                [0]=&gt;
                string(25) "2014-12-07T09:48:47-08:00"
              }
            }
          }
        }
        ["CustomField"]=&gt;
        array(1) {
          [0]=&gt;
          object(QuickBooks_IPP_Object_CustomField)#292 (1) {
            ["_data":protected]=&gt;
            array(3) {
              ["DefinitionId"]=&gt;
              array(1) {
                [0]=&gt;
                string(4) "{-1}"
              }
              ["Name"]=&gt;
              array(1) {
                [0]=&gt;
                string(6) "Crew #"
              }
              ["Type"]=&gt;
              array(1) {
                [0]=&gt;
                string(10) "StringType"
              }
            }
          }
        }
        ["DocNumber"]=&gt;
        array(1) {
          [0]=&gt;
          string(4) "1038"
        }
        ["TxnDate"]=&gt;
        array(1) {
          [0]=&gt;
          string(10) "2014-12-07"
        }
        ["Line"]=&gt;
        array(2) {
          [0]=&gt;
          object(QuickBooks_IPP_Object_Line)#263 (1) {
            ["_data":protected]=&gt;
            array(5) {
              ["Id"]=&gt;
              array(1) {
                [0]=&gt;
                string(4) "{-1}"
              }
              ["LineNum"]=&gt;
              array(1) {
                [0]=&gt;
                string(1) "1"
              }
              ["Amount"]=&gt;
              array(1) {
                [0]=&gt;
                string(9) "155555.00"
              }
              ["DetailType"]=&gt;
              array(1) {
                [0]=&gt;
                string(19) "SalesItemLineDetail"
              }
              ["SalesItemLineDetail"]=&gt;
              array(1) {
                [0]=&gt;
                object(QuickBooks_IPP_Object_SalesItemLineDetail)#765 (1) {
                  ["_data":protected]=&gt;
                  array(2) {
                    ["ItemRef"]=&gt;
                    array(1) {
                      [0]=&gt;
                      string(4) "{-3}"
                    }
                    ["TaxCodeRef"]=&gt;
                    array(1) {
                      [0]=&gt;
                      string(6) "{-NON}"
                    }
                  }
                }
              }
            }
          }
          [1]=&gt;
          object(QuickBooks_IPP_Object_Line)#748 (1) {
            ["_data":protected]=&gt;
            array(3) {
              ["Amount"]=&gt;
              array(1) {
                [0]=&gt;
                string(9) "155555.00"
              }
              ["DetailType"]=&gt;
              array(1) {
                [0]=&gt;
                string(18) "SubTotalLineDetail"
              }
              ["SubTotalLineDetail"]=&gt;
              array(1) {
                [0]=&gt;
                string(0) ""
              }
            }
          }
        }
        ["TxnTaxDetail"]=&gt;
        array(1) {
          [0]=&gt;
          object(QuickBooks_IPP_Object_TxnTaxDetail)#287 (1) {
            ["_data":protected]=&gt;
            array(1) {
              ["TotalTax"]=&gt;
              array(1) {
                [0]=&gt;
                string(1) "0"
              }
            }
          }
        }
        ["CustomerRef"]=&gt;
        array(1) {
          [0]=&gt;
          string(5) "{-11}"
        }
        ["BillAddr"]=&gt;
        array(1) {
          [0]=&gt;
          object(QuickBooks_IPP_Object_BillAddr)#284 (1) {
            ["_data":protected]=&gt;
            array(7) {
              ["Id"]=&gt;
              array(1) {
                [0]=&gt;
                string(5) "{-11}"
              }
              ["Line1"]=&gt;
              array(1) {
                [0]=&gt;
                string(13) "1045 Main St."
              }
              ["City"]=&gt;
              array(1) {
                [0]=&gt;
                string(13) "Half Moon Bay"
              }
              ["CountrySubDivisionCode"]=&gt;
              array(1) {
                [0]=&gt;
                string(2) "CA"
              }
              ["PostalCode"]=&gt;
              array(1) {
                [0]=&gt;
                string(5) "94213"
              }
              ["Lat"]=&gt;
              array(1) {
                [0]=&gt;
                string(10) "37.4559621"
              }
              ["Long"]=&gt;
              array(1) {
                [0]=&gt;
                string(11) "-122.429939"
              }
            }
          }
        }
        ["ShipAddr"]=&gt;
        array(1) {
          [0]=&gt;
          object(QuickBooks_IPP_Object_ShipAddr)#814 (1) {
            ["_data":protected]=&gt;
            array(7) {
              ["Id"]=&gt;
              array(1) {
                [0]=&gt;
                string(5) "{-11}"
              }
              ["Line1"]=&gt;
              array(1) {
                [0]=&gt;
                string(13) "1045 Main St."
              }
              ["City"]=&gt;
              array(1) {
                [0]=&gt;
                string(13) "Half Moon Bay"
              }
              ["CountrySubDivisionCode"]=&gt;
              array(1) {
                [0]=&gt;
                string(2) "CA"
              }
              ["PostalCode"]=&gt;
              array(1) {
                [0]=&gt;
                string(5) "94213"
              }
              ["Lat"]=&gt;
              array(1) {
                [0]=&gt;
                string(10) "37.4559621"
              }
              ["Long"]=&gt;
              array(1) {
                [0]=&gt;
                string(11) "-122.429939"
              }
            }
          }
        }
        ["DueDate"]=&gt;
        array(1) {
          [0]=&gt;
          string(10) "2015-01-06"
        }
        ["TotalAmt"]=&gt;
        array(1) {
          [0]=&gt;
          string(9) "155555.00"
        }
        ["ApplyTaxAfterDiscount"]=&gt;
        array(1) {
          [0]=&gt;
          string(5) "false"
        }
        ["PrintStatus"]=&gt;
        array(1) {
          [0]=&gt;
          string(11) "NeedToPrint"
        }
        ["EmailStatus"]=&gt;
        array(1) {
          [0]=&gt;
          string(6) "NotSet"
        }
        ["Balance"]=&gt;
        array(1) {
          [0]=&gt;
          string(9) "155555.00"
        }
        ["Deposit"]=&gt;
        array(1) {
          [0]=&gt;
          string(1) "0"
        }
        ["AllowIPNPayment"]=&gt;
        array(1) {
          [0]=&gt;
          string(5) "false"
        }
        ["AllowOnlinePayment"]=&gt;
        array(1) {
          [0]=&gt;
          string(5) "false"
        }
        ["AllowOnlineCreditCardPayment"]=&gt;
        array(1) {
          [0]=&gt;
          string(5) "false"
        }
        ["AllowOnlineACHPayment"]=&gt;
        array(1) {
          [0]=&gt;
          string(5) "false"
        }
      }
    }
    [1]=&gt;
    object(QuickBooks_IPP_Object_Invoice)#830 (1) {
      ["_data":protected]=&gt;
      array(22) {
      ...
      ...
  </code></pre>