diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index 5c66cf45..2a450c4c 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -133,6 +133,7 @@ class PHPExcel * */ public function disconnectWorksheets() { + $worksheet = NULL; foreach($this->_workSheetCollection as $k => &$worksheet) { $worksheet->disconnectCells(); $this->_workSheetCollection[$k] = null; @@ -141,6 +142,14 @@ class PHPExcel $this->_workSheetCollection = array(); } + /** + * Code to execute when this worksheet is unset() + * + */ + function __destruct() { + $this->disconnectWorksheets(); + } + /** * Get properties * diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 2cdaca75..c8b70fe1 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -379,13 +379,23 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable public function disconnectCells() { $this->_cellCollection->unsetWorksheetCells(); - $this->_cellCollection = null; + $this->_cellCollection = NULL; // detach ourself from the workbook, so that it can then delete this worksheet successfully $this->_parent = null; } /** + * Code to execute when this worksheet is unset() + * + */ + function __destruct() { + if ($this->_cellCollection !== NULL) { + $this->disconnectCells(); + } + } + + /** * Return the cache controller for the cell collection * * @return PHPExcel_CachedObjectStorage_xxx