-1

I had to update from PHP 7.3 to 7.4. Now I get errors, I suppose, cause I did not define the default value 0, which is a requirement in PHP 8. Here's the error:

A PHP Error was encountered

Severity: Notice

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

Filename: views/sponsorship.php

Line Number: 17
(also lines 27, 28)

Basic. it should show an empty field. When the field has a value (the name of somebody) it works fine.

Here's line 17

<th><?php echo $sponsorship['from']['id'] == $this->session->userdata('id') ? 'present to:' : 'present from:' ?></th>
जलजनक
  • 3,076
  • 2
  • 22
  • 30
Sitzbank
  • 1
  • 1
  • `Message: Trying to access array offset on value of type null` says it already. You are accessing an index which does not exist. I suppose it is `$sponsorship['from']['id']`. – Markus Zeller May 25 '22 at 10:30
  • Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-warning-undefined-arr) – Markus Zeller May 25 '22 at 10:32
  • Thanks, I m a newbie. Any suggestions on how to adapt this code? – Sitzbank May 25 '22 at 11:11
  • Just check if the key is set like `echo (isset($sponsorship['from']['id']) && $sponsorship['from']['id']) == $this->session->userdata('id') ? 'present to:' : 'present from:';`. – Markus Zeller May 25 '22 at 11:29

0 Answers0