Incompatibility in Joomla! 3.9.8 and php 7.2

Started by DashAli, 25 June 2019, 08:13:44

Previous topic - Next topic
A financial contribution is greatly appreciated as a support, to help us to keep live the project.
If you like this project you can donate some piece of BitCoin to this address: bc1qy5tgq6tvrckac2a57unxvqcnxamrvhduve9sj9

DashAli

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

A financial contribution is greatly appreciated as a support, to help us to keep live the project.
If you like this project you can donate some piece of BitCoin to this address: bc1qy5tgq6tvrckac2a57unxvqcnxamrvhduve9sj9

rogerco

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

rogerco

WHOOPS!
that should be is_Array() and is_Countable() of course.
:-[

rogerco

OK, this seems to work.

In components/com_abook/models/book.php at line 58 replace
    if(!count($this->_categories))
with
    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
    $cnt = (is_Array($rating_count) ? count($rating_count) : 0 );
    $html .= '<span itemprop="reviewCount">'.$cnt.'</span>';

or as one line
    $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
     $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

A financial contribution is greatly appreciated as a support, to help us to keep live the project.
If you like this project you can donate some piece of BitCoin to this address: bc1qy5tgq6tvrckac2a57unxvqcnxamrvhduve9sj9

federica

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.
Informatizzati [url="https://informatizzati.org"]https://informatizzati.org[/url]
Stacca la spina [url="https://disconnessi.org"]https://disconnessi.org[/url]