From 245a1dc8323af98c0a44926db6c78f06083eb8e5 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 13 Feb 2013 09:01:36 +0000 Subject: [PATCH] __destroy methods for Excel and Worksheet objects --- Classes/PHPExcel.php | 9 +++++++++ Classes/PHPExcel/Worksheet.php | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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