Useful or not, from you.
PhpSpreadsheet HLookup::hLookupSearch(..) sends wrong arguments to LookupBase::checkMatch(..).

This is:

- [X] a bug report

What is the expected behavior?

Calling $cell->getCalculatedValue() ($cell is instance of PhpOffice\PhpSpreadsheet\Cell) should work but it fails with the latest master.

What is the current behavior?

After $cell->getCalculatedValue() is called, the program fails with following error:

TypeError : PhpOffice\PhpSpreadsheet\Calculation\LookupRef\LookupBase::checkMatch(): Argument #4 ($rowKey) must be of type int, string given, called in 
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php on line 74
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php:25
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php:74
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php:45
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:4776
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3469
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3262
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:259
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:5192
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:4669
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3469
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3262
 xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:259

Here is the $cell variable value before $cell->getCalculatedValue() is called:

Screenshot 2021-05-27 at 17 25 14

And here are the values from a breakpoint right before the error is triggered at HLookup.php:73, PhpOffice\PhpSpreadsheet\Calculation\LookupRef\HLookup::hLookupSearch()

Screenshot 2021-05-27 at 17 30 04

What are the steps to reproduce?

Unfortunately, I cannot simply share the the excel file that fails because it is from one of our customers but let me know if any more information is needed apart from what was shared above. ;-)

Which versions of PhpSpreadsheet and PHP are affected?

Tested on current master branch with PHP 8.0 and 7.4.

That's a useful answer
Without any help

This is still and issue for us so I created a test excel sheet to demonstrate the problem.

Running this code:

$spreadsheet = IOFactory::load('./hlookup-test.xlsx');
$sheet = $spreadsheet->getSheet(0);
$cellVal = $sheet->getCell('H8')->getCalculatedValue();

On this excel spreadsheet: hlookup-test.xlsx

Screenshot 2021-06-14 at 16 49 22

Results in:

TypeError {#3754
  #message: "Argument 4 passed to PhpOffice\PhpSpreadsheet\Calculation\LookupRef\LookupBase::checkMatch() must be of the type int, string given, called in xxx/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php on line 74"
  #code: 0
  #file: "./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php"
  #line: 25
  trace: {
    ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php:25 { …}
    ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php:74 { …}
    ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php:45 { …}
    PhpOffice\PhpSpreadsheet\Calculation\LookupRef\HLookup::lookup() {}
    ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:4846 { …}
    ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3539 { …}
    ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php:3332 { …}
    ./vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:259 { …}
    ./src/MyNamespace/Command/TestExcel.php:30 {
      MyNamespace\Command\TestExcel->execute(InputInterface $input, OutputInterface $output): void
      › $sheet = $spreadsheet->getSheet(0);
      › $cellVal = $sheet->getCell('H8')->getCalculatedValue();
      › 
    }

ping @MarkBaker let me know if I should provide any more information ;-)