Fix #5025: Type error when sending a PM without the attachment field #5027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
There is a bug where the
pm
plugin would return fatally error in PHP 8.2 if the user doesn't have permission to add an attachment when sending a private message. This error is due to the fact that the code expects$_FILES['file_userfile']
to be an array, but this array will not be present if the user doesn't have permission to add an attachment.Fixes #5025
Description
This change adds a check before trying to iterate through
$_FILES['file_userfile']
, ensuring that it is an array before processing the attachment. If this is not an array, then no actions will be taken on$_FILES['file_userfile']
, which avoids theTypeError
.How Has This Been Tested?
The fix was manually tested in a local development environment with PHP 8.2 by sending PMs with and without the attachment permission.
Types of Changes
Checklist