Upgrade to PHP 7.2 caused error in function counting form input array
After I upgraded to 7.2 using Forge I got an error on my file upload. The form requests checks to see how many photos have been uploaded using count($this->input('photos'). This fails on 7.2 but works in 7.1 see error below.
count(): Parameter must be an array or an object that implements Countable
I'd be grateful for any advice on how to get around this problem. I tried reverting to 7.1 on Forge and then ran into other errors.
You should never update a php/mysql version on a server if you didn't test your application. But that advice is too late now.
What is the content of $this->input('photos') ? I suppose empty or null or something similar?
PHP7.1 accepts this:
count(null); // result = 0
count(0); // result = 1
count(1); // result = 1
count("string"); // result = 1
PHP7.2 does not accept this
count(null); // warning
count(0); // warning
count(1); // warning
count("string"); // warning
// Warning: count(): Parameter must be an array or an object that implements Countable in
So the fix is to first check if your variable that you want to count is an array or not.