webcomic icon indicating copy to clipboard operation
webcomic copied to clipboard

"PHP Warning: Trying to access array offset on value of type int" Across 6 Files

Open DerekPadula opened this issue 9 months ago • 2 comments

Expected Behavior
That the plugin would not generate warnings on each page load for this situation because there wouldn't be errors.

Current Behavior
My site's PHP error logs are generating a PHP warning across 6 files each time a visitor requests a Webcomic page that states the following: "PHP Warning: Trying to access array offset on value of type int". The content loads as it should, but this error still occurs. Here are the 5 files:

PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/collection/widget/class-webcomiclink.php on line 295 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/collection/widget/class-webcomiccollectionlink.php on line 173 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/taxonomy/widget/class-webcomictermlink.php on line 258 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/commerce/widget/class-webcomiccollectioncartlink.php on line 161 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/commerce/widget/class-webcomiccollectiondonationlink.php on line 161 [22-May-2024 13:50:30 UTC] PHP Warning: Trying to access array offset on value of type int in /home/websitedomain/public_html/wp-content/plugins/webcomic/lib/transcribe/widget/class-webcomictranscriptslink.php on line 169

Reproduction Steps\

Each error is related to this type of foreach loop, in the "if" section:

foreach ( $widgets as $key => $widget ) { if ( $post !== $widget['media'] ) { continue; }

		$widgets[ $key ]['media'] = 0;
	}

^ This was in /lib/transcribe/widget/class-webcomictranscriptslink.php on line 169

Suggested Fix
I'm not sure how to fix this one.

Context
Since you're not actively working on this plugin, can you provide a single fix here so that your users can make the edits as needed to the files?

Thank you.

DerekPadula avatar May 25 '24 07:05 DerekPadula