## Version 7.2 and K2

This forum is for general questions about extensions for Joomla! 3.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
borja
Joomla! Guru
Posts: 500
Joined: Wed May 27, 2009 11:26 am

### Version 7.2 and K2

Hello
I´ve got two errors on my website. The messages were something like:

com_k2/templates/default/item.php on line 248
com_k2\models\item.php on line 877

I solved theproblem but as far as I read the problem came from using the php 7.2. I had to change the code. There is not a new version of k2 since August 2017.

which is the best version of php? I read that using version php 7.1.9 it works properly.

borja
Joomla! Guru
Posts: 500
Joined: Wed May 27, 2009 11:26 am

### Re: Version 7.2 and K2

and another question. why this error appears now? I changed the php version 3 months ago and it appeared this week. cache probem?

annahersh
Joomla! Guru
Posts: 556
Joined: Wed Aug 15, 2018 8:23 pm

### Re: Version 7.2 and K2

While you have shown what files had the error, you have not stated what the error was so no one will know what to address. What was the error message?

K2 works fine with PHP 7.x

borja
Joomla! Guru
Posts: 500
Joined: Wed May 27, 2009 11:26 am

### Re: Version 7.2 and K2

This is the error that i've got: Parameter must be an array or an object that implements Countable

the problem is with this line:

if (count($item->extra_fields) && is_array($item->extra_fields)) {

extra_fields is null so it 's not possible to count in php 7.2 but it is possible to count in php 7.1.9.

SharkyKZ
Joomla! Ace
Posts: 1501
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

### Re: Version 7.2 and K2

Switch the order:

Code: Select all

if (is_array($item->extra_fields) && count($item->extra_fields)) {

annahersh
Joomla! Guru
Posts: 556
Joined: Wed Aug 15, 2018 8:23 pm

### Re: Version 7.2 and K2

@borja That K2 template you have must be from a third party. K2's coding does not use the curly bracket {, instead the colon is used in conditionals.

The original line you indicate is not written as shown in your post, in K2's item.php. It is

Code: Select all

<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
. The logic of what you show is certainly not that of any proper programmer. To count before checking for array is not logical.

borja
Joomla! Guru
Posts: 500
Joined: Wed May 27, 2009 11:26 am

### Re: Version 7.2 and K2

Hello

this line

if (count($item->extra_fields) && is_array($item->extra_fields)) {

was in:com_k2\models\item.php on line 877