Skip to content

Update for PHP 8 - unknown named parameter issue in file upload #44

Description

@njwgh

In PHP 8 an unknown named parameter error occurs with file uploads
The reason and fix:

in zebra-form.php, line 2434

actions array has this value (when uploading a file)
0 => string '_upload' (length=7)
1 => string 'desc_file_upload' (length=16)
2 => string 'move' (length=4)
3 => string 'f957_' (length=5)
'block' => string 'error' (length=5)
'message' => string 'Could not upload file' (length=21)

This array is being passed to the function _upload (via call_user_func_array)

PHP 8.0 requires that if you pass 'named' parameters - as in this case 'block' and 'message' are 'named', then the function you're passing them to has to have parameters of the same name.

_upload doesn't have these parameters named, but it actually doesn't need the 'block' and 'message' parameters, so you can leave them out
Hence you can edit line 2434 from:
if (!call_user_func_array(array(&$this,$actions[0]), array_slice($actions, 1))) {
to
if (!call_user_func_array(array(&$this,$actions[0]), array_slice($actions, 1, -2))) {

This will leave off the last two values from the end of the array.

line 2434 is used by other functions than _upload, and this fix will work for all of them EXCEPT _convert

The array sent to _convert has a lot of extra named parameters, but these aren't actually used anywhere as far as I can see so you can remove the names

so lines 3128-3131 in zebra-form.php are:
'extension' => $rule_attributes[0], // extension to convert to
'quality' => $rule_attributes[1], // quality (available only for JPEG files)
'preserve_original_file' => $rule_attributes[2], // preserve original file?
'overwrite' => $rule_attributes[3], // overwrite if file with new extension exists

they can be updated to

$rule_attributes[0], // extension to convert to
$rule_attributes[1], // quality (available only for JPEG files)
$rule_attributes[2], // preserve original file?
$rule_attributes[3], // overwrite if file with new extension exists

Note that I have tested my suggested fix for line 2434, but I haven't tested my suggested fix for lines 3128-3131

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions