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.
Post Reply
borja
Joomla! Explorer
Joomla! Explorer
Posts: 490
Joined: Wed May 27, 2009 11:26 am

Version 7.2 and K2

Post by borja » Fri Sep 14, 2018 3:36 pm

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! Explorer
Joomla! Explorer
Posts: 490
Joined: Wed May 27, 2009 11:26 am

Re: Version 7.2 and K2

Post by borja » Fri Sep 14, 2018 3:37 pm

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! Explorer
Joomla! Explorer
Posts: 283
Joined: Wed Aug 15, 2018 8:23 pm

Re: Version 7.2 and K2

Post by annahersh » Fri Sep 14, 2018 11:37 pm

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! Explorer
Joomla! Explorer
Posts: 490
Joined: Wed May 27, 2009 11:26 am

Re: Version 7.2 and K2

Post by borja » Sat Sep 15, 2018 12:48 pm

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
Joomla! Ace
Posts: 1323
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

Re: Version 7.2 and K2

Post by SharkyKZ » Sat Sep 15, 2018 1:22 pm

Switch the order:

Code: Select all

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

annahersh
Joomla! Explorer
Joomla! Explorer
Posts: 283
Joined: Wed Aug 15, 2018 8:23 pm

Re: Version 7.2 and K2

Post by annahersh » Sat Sep 15, 2018 7:46 pm

@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! Explorer
Joomla! Explorer
Posts: 490
Joined: Wed May 27, 2009 11:26 am

Re: Version 7.2 and K2

Post by borja » Tue Sep 18, 2018 2:43 pm

Hello

this line

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


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


my questions are not asked:

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

what happens with k2? the las update was onea year ago.


Post Reply

Return to “Extensions for Joomla! 3.x”