Using is_object()

Hi all am writing an app to output data as an xlsx file. The problem I am having is using is_object(). I am trying to see if an object has allready been created and if not create a new one. The following code causes an “Undefined variable: objPHPExcel in…” error

[php]if (is_object($objPHPExcel)==TRUE)
{
$num = ($objPHPExcel->getActiveSheetIndex())+1;
$objPHPExcel->setActiveSheetIndex($num);
//add array to current sheet
$objPHPExcel->getActiveSheet()->setTitle(’$nameString’);
// Create the first sheet
$objPHPExcel->getActiveSheet()->fromArray($anArray,NULL,‘A1’);
}
//if PHPExcel object has not been created - create one
else {
// Create new PHPExcel object
global $objPHPExcel;
$objPHPExcel = new PHPExcel();
etc…[/php]
Any ideas what I am doing wrong? My theory is that I am not using is_object correctly and should be using something similar to isset() but cannot find what I am looking for in any of the online resources.

For a comparison like that you want type as well as content. So

[php]if (is_object($objPHPExcel)===TRUE)[/php]

Don’t do this: global $objPHPExcel;

Thank you.

Sponsor our Newsletter | Privacy Policy | Terms of Service