1. Error: count(): parameter must be an array or an object that implements countable (view: ). as shown in Figure 1

2. Check the code implementation
count($user->address_book);
3. Print $user->address_book, its value is null
4. Adjust the code implementation, when $user->address_book is null, the expression $user->address_book ??[]equivalent to[], otherwise it is $user->address_book.
count($user->address_book ?? []);
5. In PHP 7.2.0, when the value parameter is passed into the invalid countable type, count() will now generate a warning. The version of the environment where the error occurred is PHP 7.4.26
Need long-term technical maintenance or remote troubleshooting?
I am a PHP / Go backend engineer with 15+ years of experience, focused on existing system maintenance, bug fixing, performance optimization, server troubleshooting, WordPress maintenance, and small feature iterations.
If your project is facing any of the following issues, we can start with a small troubleshooting task first:
- ✅ PHP / Laravel / Yii2 legacy systems without active maintenance
- ✅ Go / Gin backend APIs that need troubleshooting or optimization
- ✅ Slow, broken, or unstable WordPress websites
- ✅ Nginx / MySQL / Redis / Linux server issues
- ✅ CDN / Cloudflare / DNS / HTTPS configuration problems
- ✅ Long-term remote technical support or part-time maintenance
More details: About Me & Collaboration
WeChat: 13980074657
Email: shuijingwanwq@gmail.com
Telegram: @shuijingwan
GitHub: https://github.com/shuijingwan


Leave a Reply