Author Topic: Incompatibility in Joomla! 3.9.8 and php 7.2  (Read 80 times)

Offline DashAli

  • Coccinella
  • *
  • Posts: 1
  • Karma: +0/-0
Incompatibility in Joomla! 3.9.8 and php 7.2
« on: 25 June 2019, 08:13:44 »
Hi there,

there are Errors messages on the book page.
Please consider this.

I'm waiting for your new version.

thanks alot

Error by PHP 7.2.4
( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in D:\wamp64\www\mysite\components\com_abook\helpers\icon.php on line 104

Error in PHP 7.2.4
( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in D:\wamp64\www\mysite\components\com_abook\helpers\icon.php on line 138

Error in joomla! 3.9.8
( ! ) Notice: Undefined property: stdClass::$cattitle in D:\wamp64\www\mysite\components\com_abook\layouts\category\item.php on line 80

Offline rogerco

  • Coccinella
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Incompatibility in Joomla! 3.9.8 and php 7.2
« Reply #1 on: 30 July 2019, 09:39:15 »
I am getting the same warning from components/com_abook/models/book.php on line 58

This should be fairly simple to fix.
php 7.2 introduced a warning if you try to count($something) that is not countable. Typically an array is countable and the problems here are that in some circumstances the variable passed to count might be a single item rather than an array.
For 7.2 the simplest fix to to test the $something is an array before trying to count it and if it isn't setting the count to 1 (because it is probably a single item). There is a built in test isArray($something) which returns true if $something is an array and false if not.
Technically objects other than arrays can also be countable, so php7.3 has introduced a new function isCountable() which would be better to use if you are on php7.3 or higher as it would be more future proof.

I will try to remember to post a hack here when I have tested it, unless whoever is maintaining the Abook code gets around to it first. There may be other php7.2+ incompatibilities...

RogerCO

Offline rogerco

  • Coccinella
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Incompatibility in Joomla! 3.9.8 and php 7.2
« Reply #2 on: 30 July 2019, 09:44:22 »
WHOOPS!
that should be is_Array() and is_Countable() of course.
 :-[

Offline rogerco

  • Coccinella
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Incompatibility in Joomla! 3.9.8 and php 7.2
« Reply #3 on: 31 July 2019, 08:53:21 »
OK, this seems to work.

In components/com_abook/models/book.php at line 58 replace
    if(!count($this->_categories))
with
Code: [Select]
    if(!is_Array($this->_categories))
In components/com_abook/helpers/icon.php at line 138 replace
    $html .= '<span itemprop="reviewCount">'.count($rating_count).'</span>';
with
Code: [Select]
    $cnt = (is_Array($rating_count) ? count($rating_count) : 0 );
    $html .= '<span itemprop="reviewCount">'.$cnt.'</span>';
or as one line
Code: [Select]
    $html .= '<span itemprop="reviewCount">'.(is_Array($rating_count) ? count($rating_count) : 0 ).'</span>';
In components/com_abook/helpers/icon.php at line 104 replace
   $n=count($category_parent);
with
Code: [Select]
     $n = (is_Array($category_parent) ? count($category_parent) : 0);
NB if you are on php7.3+ then use is_Countable in place of is_Array as it deals with things that aren't arrays as well. In this particular instance it doesn't matter as they should always be arrays or a single item.

I've not seen the error @DashAli mentions in layouts/category/item.php and cattitle is the alias for the title field in the category model so it looks like it should work.

Hopefully these changes can get folded into an update fairly soon. I find Abook quite useful for a catalogue of books although I don't use the lending library functions.

RogerCO

Offline federica

  • Amministratore
  • Delfino
  • *****
  • Posts: 1.012
  • Karma: +1/-0
Re: Incompatibility in Joomla! 3.9.8 and php 7.2
« Reply #4 on: 31 July 2019, 11:20:01 »
Hi rogerco,
thank you very much!! I copied your fixes in my code. I hope to release a new version soon.
Al mondo ci sono 10 tipi di persone, quelli che hanno capito il codice binario e quelli che non l'hanno capito.
http://www.antivirushelp.it
stacca la spina!