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

Bug: ErrorException: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead from SYSTEMPATH\HTTP\Files\FileCollection.php at line 120 #6255

Closed
hurtsky opened this issue Jul 12, 2022 · 5 comments · Fixed by #6261
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@hurtsky
Copy link

hurtsky commented Jul 12, 2022

PHP Version

7.4

CodeIgniter4 Version

develop : ddccfc0

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

5.6

What happened?

uploading a file while using below code , will thrown ErrorException: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead.

attached screenshot:
screencapture-127-0-0-1-sstms-backend-public-user-upload-photo-2022-07-12-18_20_19

Steps to Reproduce

    public function submit_photo()
    {
        if (!$this->validate([
            'upload_file_photo' => [
                'label' => 'Upload Photo',
                'rules' => 'uploaded[upload_file_photo]'
                    . '|is_image[upload_file_photo]'
                    . '|mime_in[upload_file_photo,image/jpg,image/jpeg]'
                    . '|max_size[upload_file_photo.2048]',
            ],
        ])) {
            return redirect()->back()->with('validations', $this->validator->getErrors());
        }
        $path = WRITEPATH . 'uploads/user/' . session()->user_id . '/img';
        $file = $this->request->getFile('upload_file_photo');
        if ($file->move($path, 'profile.jpg', true)) {
            return redirect()->back()->with(
                'responses',
                'success'
            );
        }

        return redirect()->back()->with(
            'responses',
            'failed'
        );
    }

Expected Output

Should not throw ErrorException

Anything else?

No response

@hurtsky hurtsky added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 12, 2022
@hurtsky
Copy link
Author

hurtsky commented Jul 13, 2022

looks like the use of max_size rule trigger the ErrorException, removing it seems okay

@kenjis
Copy link
Member

kenjis commented Jul 13, 2022

You set max_size[upload_file_photo.2048], but the usage of max_size is like max_size[field_name,2048].

@kenjis kenjis removed the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 13, 2022
@hurtsky
Copy link
Author

hurtsky commented Jul 13, 2022

You set max_size[upload_file_photo.2048], but the usage of max_size is like max_size[field_name,2048].

Thank you!

@hurtsky hurtsky closed this as completed Jul 13, 2022
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 13, 2022
@kenjis kenjis reopened this Jul 13, 2022
@kenjis
Copy link
Member

kenjis commented Jul 13, 2022

This error message is not friendly, and it is a bug.
I sent a PR to fix it: #6261

@hurtsky
Copy link
Author

hurtsky commented Jul 13, 2022

might related to this, I just did some testing with mime_in rules, if the developer accidentally put the , to . it will throw same error. I'm not checking all the file validation rules, but might be the others rules also have this kind of error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants