If I use the module with PHP 7.2 I get this warning:

Warning: count(): Parameter must be an array or an object that implements Countable a FacetapiDependencyFacet->getDefaultSettings() (línia 139 de /var/local/html/dadesobertes/sites/all/modules/contrib/facetapi_bonus/plugins/facetapi/dependency_facet.inc).

Affected line:

if (!count($this->defaultSettings)) {

Comments

oriol_e9g created an issue. See original summary.

oriol_e9g’s picture

We need to avoid count() of non-countable objects like nulls: https://wiki.php.net/rfc/counting_non_countables

oriol_e9g’s picture

Status: Needs work » Needs review
StatusFileSize
new1.92 KB
donquixote’s picture

The patch works, but I would say it is a band-aid fix.
The real problem is that FacetapiDependencyFacet->$defaultSettings is not initialized in the constructor or in its declaration, so it will have the value NULL.

This also means that if ->settingsForm() is called before ->getDefaultSettings(), the initialization in ->getDefaultSettings() will not happen.
This is asking for trouble.

It would be great if the maintainer could illuminate us on the intention behind this.

bkosborne’s picture

StatusFileSize
new1.9 KB

There's no need for the is_array check. Instead an empty can be used instead which works with lots of different types.

vinmassaro’s picture

Status: Needs review » Reviewed & tested by the community

@bkosborne: thanks for the patch, works.

bisonbleu’s picture

Ran into this issue. Patch works for me too.

botris’s picture

Priority: Normal » Major

Moving to major, PHP 7.1 is "security fixes only", making PHP 7.2 (or higher) the natural choice for current config.

joelpittet’s picture

RTBC++

donquixote’s picture

My concern from #4 still applies, I think.

joelpittet’s picture

@donquixote you're right, maybe you could provide a patch with the place it should be initialized? It looks like it should be initalized already here:

+++ b/plugins/facetapi/dependency_facet.inc
@@ -136,13 +136,13 @@ class FacetapiDependencyFacet extends FacetapiDependency {
+        'facets' => array(),

Though it is a band-aid fix, I think it's an acceptable one considering all the changes are !count() to empty() which will produce the same value check for NULL/[]/0 as it did before 7.2

I'm still +1 on the current patch but happy to have help from @donquixote to improve on this.

firewaller’s picture

+1

darren oh’s picture

oldspot’s picture

Patch from #5 works well for me too.

drupal_lib’s picture

#5 worked for me - thanks!

joseph.olstad’s picture

RTBC +1

gdaw’s picture

I am seeing this working fine in our dev environment

RTBC+1

travis-bradbury’s picture

The concern from #4 is not wrong, but I'll give a "+1" to RTBC anyway because I think the patch preserves the original intent, which is all the issue should be obligated to do. It's bad design to have allowed the default settings to be null, but solving that doesn't have to be in the scope of this issue.

joseph.olstad’s picture

***EDIT***
see next comment
***END EDIT***

joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

actually, fixed now see commit.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.