User tests: Successful: Unsuccessful:
Status | New | ⇒ | Pending |
Category | ⇒ | Front End com_contact com_newsfeeds |
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
Labels |
Added:
?
|
I have changed the pr to use the !is_array check instead of the empty
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).
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
@mbabker I just installed 7.2 so I can now check the other possible occurrences. So should I go with your or @joomdonation suggestion
Looks like the other things I thought might be a problem were not
Use if ($this->_items === null)
.
Can we also use
if (!is_array($this->_items) && !count($this->_items))
@brianteeman Could you change the code to if ($this->_items === null) as it was agreed by Michael?
I have tested this item
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
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:
?
|
Thanks
We've got type inconsistency problems here.
$_items
is initialized as a null value and thegetItems
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).