Advertisement:

Author Topic: count(): Parameter must be an array or an object that implements Countable  (Read 4536 times)

jerry singh

  • Newbie
  • *
  • Posts: 25
That's the error am geeting in error log, osclass 3.7.4
Php am using- 7.2

count(): Parameter must be an array or an object that implements Countable in
osclass/helpers/hSearch.php on line 342

Aficionado

  • Guest
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #1 on: December 21, 2017, 06:39:25 pm »
Don't use 7.2.

PHP 7.0.x for me works 100%, some say 7.1 also works ok (not for me).


Aficionado

  • Guest
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #2 on: December 21, 2017, 06:43:01 pm »
Searching for that error with google, shows a lot of such problems. 7.2 incompatibility with older code.

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #3 on: December 23, 2017, 01:23:49 am »
Yes, this is either a bug in 7.2.0 or they really changed the way it works with null. Don't worry about it.

As I don't know yet what would be the best way to fix it (because, if it gets "fixed" in PHP 7.2.1 or so, then nothing should be fixed in Osclass part). If they make this behavior permanent in PHP, then it will be easy to deal with it, but it is best to wait for now.

Regards

jerry singh

  • Newbie
  • *
  • Posts: 25
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #4 on: December 24, 2017, 06:42:12 pm »
hi @dev101,

this bug gets fixed,
check out- https://github.com/FriendsOfPHP/Sami/issues/302
and https://github.com/FriendsOfPHP/Sami/commit/742f2575c6382c8a362c3c99974399de382bfa63
Code: [Select]
  if (null !== $this->versions && count($this->versions)) { // <= here
Code: [Select]
public function add($version, $longname = null)
     {
        if (count($this->versions)) {
        $countable = is_array($this->versions) || $this->versions instanceof \Countable;

        if ($countable && count($this->versions)) {
             throw new \LogicException('A SingleVersionCollection can only contain one Version');
         }



Code: [Select]
function osc_search_url($params = null) {
        if(is_array($params)) {
            osc_prune_array($params);
        }
        $countP = count($params);
        if ($countP == 0) { $params['page'] = 'search'; };
     

may be above solution will fixed this non-countable count($params) error  :)
« Last Edit: December 24, 2017, 06:47:55 pm by jerry singh »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #5 on: December 24, 2017, 07:13:33 pm »
I don't see it on bugs.php.net.

jerry singh

  • Newbie
  • *
  • Posts: 25
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #6 on: December 24, 2017, 07:19:33 pm »
may be its not bug; of php 7.2

error occured due to updating newer version of php.

please have a look - https://github.com/FriendsOfPHP/Sami/issues/302
and https://github.com/FriendsOfPHP/Sami/commit/742f2575c6382c8a362c3c99974399de382bfa63

hope this will help you to sort out this error.  :)

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #7 on: December 24, 2017, 07:27:38 pm »
I'm only interested in official PHP bug tracker, not other unrelated projects.

Aficionado

  • Guest
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #8 on: December 24, 2017, 08:04:20 pm »
Nothing needs to be sorted out for now. Just use PHP 7.0.x.

Simple as that.
« Last Edit: December 24, 2017, 08:05:52 pm by Aficionado »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #9 on: December 25, 2017, 04:58:30 pm »
I have tested PHP 7.2.1 RC1 and seems to behave the same.
This change will not break things, as return is still 0 (same as before), but with annoying warning. Even empty strings will raise it.

So, the easiest fix for this is to replace:

Code: [Select]
function osc_search_url($params = null) {
with:

Code: [Select]
function osc_search_url($params = array()) {
lazy alternative:

Code: [Select]
function osc_search_url(@$params = null) {
Regards

jerry singh

  • Newbie
  • *
  • Posts: 25
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #10 on: December 26, 2017, 05:25:01 pm »
 :)
@dev101

thanks! for sort out this error,  but  still theres lot of issue with php 7.2 (osclass) :D

Aficionado

  • Guest
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #11 on: December 26, 2017, 05:31:00 pm »
:)
@dev101

thanks! for sort out this error,  but  still theres lot of issue with php 7.2 (osclass) :D

Then don't use 7.2. If you are not just testing, don't use it. Use 7.0.x.

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #12 on: December 26, 2017, 09:53:42 pm »
I have briefly tested 7.2.0 and besides this one, one other thing needs fixing, but didn't notice other issues (though it was a brief test).
Your issue with HTTP_HOST in other topic might not directly be related to PHP 7.2.0 (I don't see why it should be), and for other issues you have regarding PHP 7.2 you can report in new separate topics here or at github.


dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: count(): Parameter must be an array or an object that implements Countable
« Reply #14 on: December 26, 2017, 10:44:34 pm »
Thanks, I've read it before, but forgot it in the meantime...