I’m trying to pass an object to a function in PHP to split a long function. The first example is the working way with the long funcion:
public function import() {
$this->importSections();
}
public function importSections() {
$reader = new PhpOfficePhpSpreadsheetReaderXlsx();
$spreadsheet = $reader->load($this->_file);
$sheet = $spreadsheet->getSheetByName('Sections');
$highestRow = $sheet->getHighestDataRow(); // <- this works
// ... //
}
However, I get the Error Call to a member function getHighestDataRow() on string on the above marked line if I try to split the function and pass the sheet like this:
public function import() {
$reader = new PhpOfficePhpSpreadsheetReaderXlsx();
$spreadsheet = $reader->load($this->_file);
$sheet = $spreadsheet->getSheetByName('Sections');
$this->importSections($sheet);
}
public function importSections($sheet) {
$highestRow = $sheet->getHighestDataRow(); // <- Error
// ... //
}
And if I explicitly pass it by reference like this..:
public function import() {
$reader = new PhpOfficePhpSpreadsheetReaderXlsx();
$spreadsheet = $reader->load($this->_file);
$sheet = $spreadsheet->getSheetByName('Sections');
$this->importSections($sheet);
}
public function importSections(&$sheet) {
$highestRow = $sheet->getHighestDataRow(); // <- Error
// ... //
}
…I get the error Argument #1 ($sheet) could not be passed by reference.
Can someone please explain what is going on here?