-2

OS: Windows 11 PHP Version 8.1.6

Error Mesage: Deprecated: Implicit conversion from float 65.03846153846153 to int loses precision in C:\xampp\htdocs\sati\import\excel_reader2.php on line 922

public function __construct($file='',$store_extended_info=true,$outputEncoding='') {

  $this->_ole = new OLERead();
  $this->setUTFEncoder('iconv');
  if ($outputEncoding != '') { 
    $this->setOutputEncoding($outputEncoding);
  }
  for ($i=1; $i<245; $i++) {
    $name = strtolower(( (($i-1)/26>=1)?chr(($i-1)/26+64):'') . chr(($i-1)%26+65));  //line 922
    $this->colnames[$name] = $i;
    $this->colindexes[$i] = $name;
  }
  $this->store_extended_info = $store_extended_info;
  if ($file!="") {
    $this->read($file);
  }
}

Anyone have ideia to fix the problem?

2 Answers2

0

Yes, it's deprecated

You should cast your calculations to ints when passing into chr():

strtolower(
    (
        ($i-1)/26>=1
            ? chr((int) ($i-1)/26+64)
            : ''
    )
    . chr((int) ($i-1)%26+65)
)
Justinas
  • 41,402
  • 5
  • 66
  • 96
0

Fixed function

/**
* Constructor
*
* Some basic initialisation
*/
//function Spreadsheet_Excel_Reader($file='',$store_extended_info=true,$outputEncoding='') { // DEPRECATED EDITED IN 06-2020
    public function __construct($file='',$store_extended_info=true,$outputEncoding='') {    
        $this->_ole = new OLERead();
        $this->setUTFEncoder('iconv');
        if ($outputEncoding != '') { 
            $this->setOutputEncoding($outputEncoding);
        }
        for ($i=1; $i<245; $i++) {
            //$name = strtolower(( (($i-1)/26>=1)?chr(($i-1)/26+64):'') . chr(($i-1)%26+65)); // DEPRECATED EDITED IN 07-2022
            $name = strtolower(( (($i-1)/26>=1)? chr((int) (($i-1)/26+64)) :'') . chr((int) (($i-1)%26+65)) );
            $this->colnames[$name] = $i;
            $this->colindexes[$i] = $name;
        }
        $this->store_extended_info = $store_extended_info;
        if ($file!="") {
            $this->read($file);
        }
    }