? ? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
22 Dec 2017

PR for #19125
PR for #19126

Can you please test this @Quy - I dont have php 7.2 installed yet

If these work then there are lots of other places to be fixed

avatar brianteeman brianteeman - open - 22 Dec 2017
avatar brianteeman brianteeman - change - 22 Dec 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 22 Dec 2017
Category Front End com_contact com_newsfeeds
avatar mbabker
mbabker - comment - 22 Dec 2017

We've got type inconsistency problems here. $_items is initialized as a null value and the getItems method sets it to be either an array or a boolean false. Only the array can be counted.

An empty check might silence the warning, but it really isn't a great fix. If we're going to keep setting that value as something other than an array, then I'd make the check !is_array($this->_items) otherwise we need to do something so it is always an array and handle error cases another way (which probably has B/C issues).

avatar brianteeman
brianteeman - comment - 22 Dec 2017

I suspect that there are a lot of places that a fix will be needed. What I did was just to test. I found two different methods being used in other projects. The one I used here and the one you suggest.

As I dont have php 7.2 installed yet its hard for me to test

avatar brianteeman brianteeman - change - 22 Dec 2017
Labels Added: ?
avatar brianteeman
brianteeman - comment - 22 Dec 2017

I have changed the pr to use the !is_array check instead of the empty

avatar joomdonation
joomdonation - comment - 22 Dec 2017

@mbabker isn't if ($this->_items === null) better check?

avatar mbabker
mbabker - comment - 22 Dec 2017

Honestly, both would result in the same right now. We really should refactor this code to use a consistent type and implement better error handling logic, but that type of work would need to go into 4.0 because there will be B/C implications (getItems() should not be able to return an array or boolean false, it should always be an array but then we need to communicate error state too, whether that means use of getError()/setError() or throwing an exception is to be determined).

avatar joomdonation
joomdonation - comment - 22 Dec 2017

Yes. Both would prevent the warning. However, in theory, if someone creates the model object and calls the method gettems() two times (stupid, I know)

$model->getItems();
$model->getItems();

With is_array check, the second call, the code will still be executed. But with === null, the method will just return $this->_items directly, that's why I think === null is a better check

avatar brianteeman
brianteeman - comment - 22 Dec 2017

@mbabker I just installed 7.2 so I can now check the other possible occurrences. So should I go with your or @joomdonation suggestion

avatar brianteeman
brianteeman - comment - 22 Dec 2017

Looks like the other things I thought might be a problem were not

avatar mbabker
mbabker - comment - 23 Dec 2017

Use if ($this->_items === null).

avatar Anu1601CS
Anu1601CS - comment - 26 Dec 2017

Can we also use
if (!is_array($this->_items) && !count($this->_items))


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19135.
avatar joomdonation
joomdonation - comment - 2 Jan 2018

@brianteeman Could you change the code to if ($this->_items === null) as it was agreed by Michael?

avatar Quy Quy - test_item - 3 Jan 2018 - Tested successfully
avatar Quy
Quy - comment - 3 Jan 2018

I have tested this item successfully on 97e3740


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19135.

avatar joomdonation joomdonation - test_item - 3 Jan 2018 - Tested successfully
avatar joomdonation
joomdonation - comment - 3 Jan 2018

I have tested this item successfully on 97e3740


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19135.

avatar Quy Quy - change - 3 Jan 2018
Status Pending Ready to Commit
avatar Quy
Quy - comment - 3 Jan 2018

RTC

avatar mbabker mbabker - change - 8 Jan 2018
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2018-01-08 17:13:04
Closed_By mbabker
Labels Added: ?
avatar mbabker mbabker - close - 8 Jan 2018
avatar mbabker mbabker - merge - 8 Jan 2018
avatar brianteeman
brianteeman - comment - 8 Jan 2018

Thanks

Add a Comment

Login with GitHub to post a comment