aVadim483 / fast-excel-reader

Lightwight and very fast XLSX Excel Spreadsheet Reader in PHP
MIT License
63 stars 16 forks source link

Prevent TypeError in Sheet::isActive() #31

Open BlackbitDevs opened 1 week ago

BlackbitDevs commented 1 week ago

In https://github.com/aVadim483/fast-excel-reader/blob/53b2725954cabfa898b67e76ea36e873e870ad19/src/FastExcelReader/Sheet.php#L295-L302 $this->active gets set via https://github.com/aVadim483/fast-excel-reader/blob/53b2725954cabfa898b67e76ea36e873e870ad19/src/FastExcelReader/Sheet.php#L374

But if this line does not get executed, $this->active stays null which results in a PHP TypeError (because the method is required to return bool). Am not sure if this is the desired behaviour or in other words if https://github.com/aVadim483/fast-excel-reader/blob/53b2725954cabfa898b67e76ea36e873e870ad19/src/FastExcelReader/Sheet.php#L373-L375 actually should get executed for EVERY valid Excel file. But in our case it was not.

PS: I stumbled upon the int-cast. The method isActive() returns boolean but _readHeader() contains $this->active = (int)$xmlReader->getAttribute('tabSelected'); - how can $this->active actually become a bool?

HergenD commented 5 hours ago

PS: I stumbled upon the int-cast. The method isActive() returns boolean but _readHeader() contains $this->active = (int)$xmlReader->getAttribute('tabSelected'); - how can $this->active actually become a bool?

protected ?bool $active = null;

Any int value gets juggled to a boolean value when assigned to a typed (boolean) property

So $this->active = 1 // true $this->active = 0 // false $this->active = 420 // true