This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

mwindey

  • *****
  • 465 posts
PHP 8 Warning: Undefined array key 0
« on: September 28, 2022, 04:49:46 PM »
Not an error just a warning in apache logs with php 8

[Wed Sep 28 16:30:07.156221 2022] [lsapi:warn] [pid 152464:tid 140099836679936] [client 2a01:4f7:6a:14d4::2:45548] [host ***.be] Backend log: PHP Warning:  Undefined array key 0 in /home/u4417******/domains/w***.be/public_html/oc-content/plugins/share/functions.php on line 65\n

Line 65 is:   $stats = ModelSR::newInstance()->getStats($item_id)[0];

Any suggestion on how to get rid of the warning?
« Last Edit: September 28, 2022, 04:52:33 PM by mwindey »

*

MB Themes

Re: PHP 8 Warning: Undefined array key 0
« Reply #1 on: September 28, 2022, 05:07:01 PM »
Code: [Select]
$stats = @ModelSR::newInstance()->getStats($item_id)[0];
or

Code: [Select]
  $stats_data = ModelSR::newInstance()->getStats($item_id);
  $stats = (isset($stats_data[0]) ? $stats_data[0] : array());
« Last Edit: September 28, 2022, 05:09:14 PM by MB Themes »
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 465 posts
Re: PHP 8 Warning: Undefined array key 0
« Reply #2 on: September 28, 2022, 06:30:59 PM »
@MB Themes,

Thanks!  ;) First one solved....
One more in next line is:
Backend log: PHP Warning:  Undefined array key "i_fb_clicks" in /home/u44173p136925/domains/***.be/public_html/oc-content/plugins/share/functions.php on line 77\n

Where line 77 is:
Code: [Select]
    if($facebook == 1) {
       $text[] = ($stats['i_fb_clicks'] == '' ? 0 : $stats['i_fb_clicks']) . ' ' . __('Facebook clicks', 'share');
    }

Marked as best answer by frosticek on September 30, 2022, 12:34:18 PM
*

MB Themes

Re: PHP 8 Warning: Undefined array key 0
« Reply #3 on: September 29, 2022, 09:07:37 AM »
@mwindey
Updated plugin.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 465 posts
Re: PHP 8 Warning: Undefined array key 0
« Reply #4 on: September 29, 2022, 04:19:39 PM »
@MB Themes

Super! Thank you  :-*