nuovo/spreadsheet-reader

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP

Opened this issue ยท 5 comments

OS: Windows 7
PHP Version: PHP 7.0.1RC1

Error message:
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OLERead has a deprecated constructor in C:\Users\ADMIN\Desktop\php-excel-reader\excel_reader2.php on line 95

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Spreadsheet_Excel_Reader has a deprecated constructor in C:\Users\ADMIN\Desktop\php-excel-reader\excel_reader2.php on line 312

excel_reader2.php :

turn off : //function OLERead(){ }

and change :
```
/**
* Constructor
*
* Some basic initialisation

function Spreadsheet_Excel_Reader($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));
        $this->colnames[$name] = $i;
        $this->colindexes[$i] = $name;
    }
    $this->store_extended_info = $store_extended_info;
    if ($file!="") {
        $this->read($file);
    }
} */

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));
$this->colnames[$name] = $i;
$this->colindexes[$i] = $name;
}
$this->store_extended_info = $store_extended_info;
if ($file!="") {
$this->read($file);
}
}

and how to turn off : //function OLERead(){ }?

Awesome! This worked!

Just to clarify for anyone who is confused, inside class OLERead (line 96 for me) there is a line that says function OLERead() { } (line 98) just comment that out.

Then on line 918 comment out the entire function Spreadsheet_Excel_Reader and add the new construct that fahizalcode posted above.

Also if you are getting this deprecation warning, it is likely you will also get a notification about split(); just replace split( with explode( (lines 80, 847) and you should be good

Just to clarify for anyone who is confused, inside class OLERead (line 96 for me) there is a line that says function OLERead() { } (line 97) just comment that out. //function OLERead(){ }
Then on line 915 comment out the entire function Spreadsheet_Excel_Reader and add the new construct
comment below code--
/*function Spreadsheet_Excel_Reader($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));
$this->colnames[$name] = $i;
$this->colindexes[$i] = $name;
}
$this->store_extended_info = $store_extended_info;
if ($file!="") {
$this->read($file);
}
} */
add paste this code after above commented code
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));
$this->colnames[$name] = $i;
$this->colindexes[$i] = $name;
}
$this->store_extended_info = $store_extended_info;
if ($file!="") {
$this->read($file);
}
}

excel_reader2.php :

turn off : //function OLERead(){ }

and change :

/**
* Constructor
*
* Some basic initialisation

function Spreadsheet_Excel_Reader($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));
$this->colnames[$name] = $i;
$this->colindexes[$i] = $name;
}
$this->store_extended_info = $store_extended_info;
if ($file!="") {
$this->read($file);
}
} */


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));
$this->colnames[$name] = $i;
$this->colindexes[$i] = $name;
}
$this->store_extended_info = $store_extended_info;
if ($file!="") {
$this->read($file);
}
}

Thank you it works perfectly fine. just to confirm 1 more thing

PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Spreadsheet_Excel_Reader has a deprecated constructor in /home/websitename/public_html/onlinetest/importfile/Excel/reader.php on line 326

although the code is working fine but still getting the above error. Please help me tho resolve this error also.