Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to access array offset on value of type null PHP 7.4.13 #2026

Closed
safuandgb opened this issue Apr 26, 2021 · 17 comments
Closed

Trying to access array offset on value of type null PHP 7.4.13 #2026

safuandgb opened this issue Apr 26, 2021 · 17 comments

Comments

@safuandgb
Copy link

safuandgb commented Apr 26, 2021

This is:

- [X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Read the excel file

What is the current behavior?

ErrorException : Trying to access array offset on value of type null

What are the steps to reproduce?

$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load(storage_path('template.xls'));

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

public function test()
{

    $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load(storage_path('template.xls'));

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet v 1.16
PHP 7.4

@darkojelen
Copy link

I’m dealing with similar problem. After upgrading to PHP 7.4

code

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load('file.xlsx');

produce in log file endless lines of

[28-Apr-2021 09:12:45] PHP Notice: Trying to access array offset on value of type int in /php/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php on line 56

@oleibman
Copy link
Collaborator

Can either of you share the file which is causing this problem? And please confirm your version of PhpSpreadsheet.

@darkojelen
Copy link

I hope that this could help.

example.zip

@oleibman
Copy link
Collaborator

No luck duplicating your problem with read-x.php as you supplied it on any of master, 17.1, or 16.0 releases, running with PHP 7.4.14. Results in each case:

array(2) {
  [0]=>
  int(1)
  [1]=>
  array(1) {
    [1]=>
    array(1) {
      ["A"]=>
      string(1) "A"
    }
  }
}

@safuandgb
Copy link
Author

safuandgb commented May 21, 2021

Hi @oleibman ,

Did you enable your notice error reporing?

The output for read-x.php using PHP 7.4.13 is

$ php read-x.php
PHP Notice:  Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 133

Notice: Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 133
PHP Notice:  Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 134

Notice: Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 134
PHP Notice:  Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 137

Notice: Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 137
PHP Notice:  Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 138

Notice: Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 138
PHP Notice:  Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 144

Notice: Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 144
PHP Notice:  Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 145

Notice: Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 145
PHP Notice:  Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 146

Notice: Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 146
PHP Notice:  Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 147

Notice: Trying to access array offset on value of type null in C:\Users\dgb\Desktop\Workspace\example\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx\Styles.php on line 147
array(2) {
  [0]=>
  int(1)
  [1]=>
  array(1) {
    [1]=>
    array(1) {
      ["A"]=>
      string(1) "A"
    }
  }
}

@oleibman
Copy link
Collaborator

I added the following statements:

	echo $name;
	echo 'abc'{1}, "\n";

And my output is now:

Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\git\example\read-x.php on line 18
array(2) {
  [0]=>
  int(1)
  [1]=>
  array(1) {
    [1]=>
    array(1) {
      ["A"]=>
      string(1) "A"
    }
  }
}

Notice: Undefined variable: name in C:\git\example\read-x.php on line 17
b

So, yes, I get notices, but I don't see the notices you are reporting.

@wacekgocki
Copy link

I have the same problem. My error message is: 'Trying to access array offset on value of type int' (errcode: 0).

I'm calling function:

$sheet->setCellValueByColumnAndRow(1, 1, 100);

Then execution goes down to method DefaultValueBinder::dataTypeForValue. Error occurs in line:

} elseif ($pValue[0] === '=' && strlen($pValue) > 1) {

The reason of error is that my $pValue is of type int and above line tries to use it as an array ($pValue[0]), which is not allowed for type int. In my opinion the above line should look like this:

} elseif (is_string($pValue) && $pValue[0] === '=' && strlen($pValue) > 1) {

@MarkBaker
Copy link
Member

MarkBaker commented Jun 30, 2021

Then execution goes down to method DefaultValueBinder::dataTypeForValue. Error occurs in line:
} elseif ($pValue[0] === '=' && strlen($pValue) > 1) {

That line of code was fixed in version 1.10.0, 18 months ago

@wacekgocki
Copy link

OK, my fault, sorry. I did 'composer update' before making a comment, but did not check that it stuck on version 1.9.0 because of a problem with some other dependencies. Now I have 1.18.0 and my problem is gone. Thanks.

@austyking
Copy link

austyking commented Sep 4, 2021

This is:

- [X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Read the excel file

What is the current behavior?

ErrorException : Trying to access array offset on value of type null

What are the steps to reproduce?

$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load(storage_path('template.xls'));

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

public function test()
{

    $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load(storage_path('template.xls'));

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet v 1.16
PHP 7.4

Has this issue been fixed now? Or any work around?
I updated to version 1.18.0 but still have this issue on PHP 7.4

@flickervale
Copy link

I had an issue :

Severity: Notice
Message: Trying to access array offset on value of type null
Filename: Xlsx/Styles.php
Line Number: 133

After this line:

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();

I add with this line:

$reader->setReadDataOnly(true);

Just like this:

$file = $_FILES['file']['tmp_name'];
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($file);
$sheetData = $spreadsheet->getActiveSheet()->toArray();

And this works for me.

@ytilotti
Copy link

Same issue here with error Trying to access array offset on value of type null on PHP 7.4.25 and PhpSpreadsheet 1.9.

1. Upgrade PhpSpreadsheet 1.16

Working, no error, file readable

2. Upgrade PhpSpreadsheet 1.17

Working, no error, file readable

3. Upgrade PhpSpreadsheet 1.18

Not working, error Argument 4 passed to PhpOffice\PhpSpreadsheet\Calculation\LookupRef\LookupBase::checkMatch() must be of the type int, string given fixed by #2123

4. Upgrade PhpSpreadsheet 1.19

No error but file not working, impossible to open with Excel.

@oleibman
Copy link
Collaborator

I still am unable to duplicate the error, with any release, of the only file uploaded so far in connection with this problem. If you have another file with a problem, please upload it.

@ytilotti
Copy link

Sorry @oleibman, I can't share my file and script.
I compare between 1.18 & 1.19 but so much changes to find a way.
I will stay in 1.17 for the moment.

I make some tests. I cleared my script and deleted all cell/col/sheet in my file. I only open/write with this code:

$file = 'template.xlsx';
$writer = IOFactory::load($file);
$writerSave = IOFactory::createWriter($writer, 'Xlsx');
$writerSave->setPreCalculateFormulas(true);
$writerSave->save('test.xlsx');
unlink($file);
unset($writer, $writerSave);

I can open the file. I don't know if the problem is on reading or writing.

@mikevaux
Copy link

A couple of things to add to this thread (I was experiencing the same behaviour as OP)

@ytilotti
Copy link

I agree with @mikevaux. I have tested with 1.20.0 and all is fine.

@oleibman
Copy link
Collaborator

Thank you for confirming that the issue is resolved. Closing it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

9 participants