Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
njwgh opened this issue Aug 3, 2022 · 1 comment
Open

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

njwgh opened this issue Aug 3, 2022 · 1 comment

Comments

@njwgh
Copy link

njwgh commented Aug 3, 2022

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

@stefangabos
Copy link
Owner

hey, thanks for letting me know!
i think the easiest fix is to change

if (!call_user_func_array(array(&$this,$actions[0]), array_slice($actions, 1))) {

to

if (!call_user_func_array(array(&$this,$actions[0]), array_values(array_slice($actions, 1)))) {

that array_values would take care of the named parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants