PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable after upgrade to Suite 7.14

Hi,

I had an backup of a 7.10.25 installation working under php 7.4 and mysql 5.7.
I restored it and upgraded it step by step to SuiteCRM 7.14.2 in order to have an ESR version with up to date php and mysql.

At first look, my installation looks working with 7.14.2, ubuntu server 22.04 for raspberry 4, php 8.1 and mysql 8.1 (default one on my system).

However, the diagnostic tool hangs at 0 % (owner’s rights double-checked and quick repair done).
But my main issue is a blank screen that does appear after csv download for example.

My apache log say "PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable...". A quick research send me to the same kind of issue but for previous versiond. The solution was to go back to php 7.4. :unamused:

However, this php version does not appear in the compatibility matrix. :confused:
Are there common instructions to enter in mysql console ? Any clue would be welcome. :+1:

Regards

Do not hesitate to point me any webpage that can help :pray:

It would be helpful if that error had a filename and a line number, so we can know the place in the code where that is happening. Better yet, if we had a stack trace to go with it, to see where it is being called from.

Sorry, my fault.
I believed it was something quite common after upgrading the sql version.
Here is the full php apache log when I try to import targets from a csv :

[Thu Dec 14 19:43:01.002817 2023] [php:error] [pid 35371] [client 127.0.0.1:45634] 
PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /var/www/website.domaine.com/modules/Import/views/ImportListView.php:131

Stack trace:
#0 /var/www/website.domaine.com/modules/Import/views/view.last.php(189): ImportListView->display()
#1 /var/www/website.domaine.com/modules/Import/views/view.last.php(141): ImportViewLast->getListViewTableFromFile()
#2 /var/www/website.domaine.com/include/MVC/View/SugarView.php(210): ImportViewLast->display()
#3 /var/www/website.domaine.com/include/MVC/Controller/SugarController.php(432): SugarView->process()
#4 /var/www/website.domaine.com/include/MVC/Controller/SugarController.php(363): SugarController->processView()
#5 /var/www/website.domaine.com/include/MVC/SugarApplication.php(101): SugarController->execute()
#6 /var/www/website.domaine.com/index.php(52): SugarApplication->execute()
#7 {main}\n  thrown in /var/www/website.domaine.com/modules/Import/views/ImportListView.php on line 131, referer: https://website.domaine.com/index.php`

Big thank you

That should be easy to fix to avoid the FATAL, although I am not sure what consequences there are of reaching that point in the code without a valid value in that variable.

Can you please try the following change and tell me how it goes for you?

Comparing salesagility:hotfix...pgorod:patch-16 · salesagility/SuiteCRM · GitHub

Try it with both PHP 7.4 and 8.x, please

1 Like

Error:
$this->ss->assign('colCount', is_countable($this->headerColumns) ? count($this->headerColumns : 0));
Fixed:
$this->ss->assign('colCount', is_countable($this->headerColumns) ? count($this->headerColumns) : 0);

1 Like

Hi,

The fix proposed by @chris001 is necessary indeed.
And it works under php 7.4 and php 8.X

FYI : There is no need of change of …/modules/Import/views/ImportListView.php with php 7.4.

I’d rather stay on php 8.1 to respect the compatibility matrix and will continue to experience and report.
(ie diagnostic tool)

Thank you very much.

1 Like

Is Chris’ solution different than mine?

Just checking to know if I should open the PR with that commit

I went ahead and did it

1 Like

I made a comment on there. Have to move one of the ) to make it work.

2 Likes

Thanks, I guess I was distracted there for a bit. :blush:

Fixed.

1 Like