0

I switch to PHP 7.3 and i get the same problem like other people on this error ( Parameter must be an array.. .)

I try to modify without success so i post this post.

My code is :

$i = $this->show($user->id);
$a = json_decode($i);

for ($b = 0; $b < sizeof($a->data); $b++)

The error it's from the "for".

I use Laravel.

Do you know how can i modify this line?

Thnks

Rwd
  • 34,180
  • 6
  • 64
  • 78
Mnk
  • 1
  • 3
  • Could you insert a var_dump($a); and tell us the result? – Stratadox Dec 23 '19 at 15:44
  • i try with "var_dump($a->data);" and i get "NULL" – Mnk Dec 23 '19 at 16:00
  • What is `$i` meant to be? – Rwd Dec 23 '19 at 16:04
  • When I upgraded to 7.2 I had to go through my codebase and change several instances like this to include null checks. In previous versions it was acceptable but now it isn't. `sizeof` or `count` expect an array or something that implements `Countable`- [docs](https://www.php.net/manual/en/function.count.php) – Brian Thompson Dec 23 '19 at 16:04
  • Rwd: $i it's the id of the user ( from CRM Database) – Mnk Dec 23 '19 at 16:09
  • Are there times when it can be `null`? – Rwd Dec 23 '19 at 16:13
  • Sorry i was wrong. This is the code: $i=$this->show($user->id); //var_dump($i); $a=json_decode($i); So $i it's the user ID (working) and $a it's json_decode form him The var dump of $i it's working but the $a (json_decode) return NULL I hope I expressed myself well – Mnk Dec 23 '19 at 16:17
  • So `$i` isn't `JSON`? Please can you show the output of `var_dump($i);`. – Rwd Dec 23 '19 at 16:31
  • What is `show()` method? – Wahyu Kristianto Dec 23 '19 at 18:45
  • I think i understand a little bit more. When i decompose the code. With '$i=$this->show($user->id);' i get 'DATA:NULL'. So when i do '$a=json_decode($i); ' i get 'Null' when i call '$a' I think it's the reason of my bug but i still don't know how to fix this with the new php version. 'for( $b=0; $bdata); $b++ )' I suppose the 'sizeof' don't understand the result 'NULL' and display 'sizeof(): Parameter must be an array or an object that implements Countable' Solution ? – Mnk Dec 24 '19 at 09:41
  • RWD: `var_dump($i);` give string(118) "{"success":true,"data":null,"additional_data":{"pagination":{"start":0,"limit":200,"more_items_in_collection":false}}}" – Mnk Dec 24 '19 at 09:48

1 Answers1

0

So first, thanks for your help.

Second: I found the solution and you know what ? is not the code ... but the database.

After few hours to search i found some structure problem in my database. So i fix it i try again the script and ... Work.

I close this post.

Mnk
  • 1
  • 3