Alexandria Book Library > Errori (Bugs)

Incompatibility in Joomla! 3.9.8 and php 7.2

(1/1)

DashAli:
Hi there,

there are Errors messages on the book page.

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 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

--- Code: ---    if(!is_Array($this->_categories)) --- End code --- In components/com_abook/helpers/icon.php at line 138 replace$html .= '<span itemprop="reviewCount">'.count($rating_count).'</span>'; with --- Code: ---$cnt = (is_Array($rating_count) ? count($rating_count) : 0 );
$html .= '<span itemprop="reviewCount">'.$cnt.'</span>';

--- End code ---
or as one line

--- Code: ---    $html .= '<span itemprop="reviewCount">'.(is_Array($rating_count) ? count($rating_count) : 0 ).'</span>'; --- End code --- In components/com_abook/helpers/icon.php at line 104 replace$n=count($category_parent); with --- Code: ---$n = (is_Array($category_parent) ? count($category_parent) : 0);
--- End code ---

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

federica:
Hi rogerco,
thank you very much!! I copied your fixes in my code. I hope to release a new version soon.