将参数传递给对象

to get cell from xls

$filename = "upload/" . $nfile;
$type = PHPExcel_IOFactory::identify($filename);
$objReader = PHPExcel_IOFactory::createReader($type);
$objPHPExcel = $objReader->load($filename);
$array = ($objPHPExcel->getSheetNames());
$finarr = [];

It's works.

To get value of cell from Excel by PHPExcel:

foreach($sheetNames as $singleSheetName => $value){
    $vz = ($objPHPExcel->getSheet($singleSheetName)->getCell('L40')->getCalculatedValue());
    return $firarr[$vz];
}

It's works.

I want to optimize code. create a function

function getCorrectCell($a, $b) {
     return ($objPHPExcel->getSheet($a)->getCell($b)->getCalculatedValue());
};

I call getCorrectCell($singleSheetName, 'L40');

error

Got error

PHP message: PHP Notice: Undefined variable: objPHPExcel in /var/www/******/html/secondworker.php on line 13
PHP message: PHP Fatal error: Call to a member function getSheet() on null

How to correctly declarate function and put arguments? Thanks for help!