While install Drupal 8.4.3 in PHP 7.2 environment, this warning is occurred.
Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Form\FormValidator->doValidateForm() (line 260 of core/lib/Drupal/Core/Form/FormValidator.php).
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 239)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 239)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 239)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'install_configure_form') (Line: 119)
Drupal\Core\Form\FormValidator->validateForm('install_configure_form', Array, Object) (Line: 571)
Drupal\Core\Form\FormBuilder->processForm('install_configure_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('install_configure_form', Object) (Line: 899)
install_get_form('Drupal\Core\Installer\Form\SiteConfigureForm', Array) (Line: 593)
install_run_task(Array, Array) (Line: 549)
install_run_tasks(Array) (Line: 117)
install_drupal(Object) (Line: 44)
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | count-warnings-php72-2932916-7.patch | 6.82 KB | oriol_e9g |
Comments
Comment #2
tibezh commentedSeems this issue is duplicated
Look at #2928846: [PHP 7.2] count() parameter must be an array or an object that implements Countable
Comment #3
avpadernoComment #4
hanoiiWell, although related, I don't think it's a duplicate and the other issue was fixed and was for some tests.
This happened for me as well and it's on the actual code, not tests. I still think is valid.
Comment #5
andypostRelated conversion
Comment #6
n_deshev commentedThe issue is relevant and it affects D 7.x too. After updating to PHP 7.2 I get a warning on clean D7 install:
Warning: count(): Parameter must be an array or an object that implements Countable in _form_validate() (line 1441 of /var/www/docroot/web/includes/form.inc).Comment #7
oriol_e9gOK. Try with this.
Comment #9
David_Rothstein commentedFor Drupal 7 there is already an issue for this at #2885610: [PHP 7.2] Avoid count() calls on uncountable variables - let's combine work over there.
For Drupal 8, it's a duplicate also, but the wrong issue was linked to above. #2915820: [PHP 7.2] FormValidator: Parameter must be an array or an object that implements Countable is the actual issue where the error described in the issue summary was fixed in 8.5.x. It looks like a decision was made there not to backport to 8.4.x.
Comment #10
joseph.olstadpatch at #2885610: [PHP 7.2] Avoid count() calls on uncountable variables
looks like it is good, what would we need from#7 several errors?
also, regarding #7
is_array by it'self is costly, see
#2863786: D7 ThemeRegistry array_key_exists() micro-optimization
and
#2770065: array_key_exists() micro-optimization
Comment #11
joseph.olstadI reviewed patch #7 ,
I don't recommend we take anything from this.have not yet determined if there is anything we can take from this patchquery condition is already countable, does not throw warnings. D7 condition is implemented in a similar way to D8 and D8 uses count() for this. I checked the 8.6.x branch code on this and compared with 7.x and looked at the various query classes and interfaces and implements interface, not only that, I don't see any mention of this actually happening in the wild.
I am curious now to try combining
#2885610: [PHP 7.2] Avoid count() calls on uncountable variables
with
#2925449: [PHP 7] Function each() is deprecated since PHP 7.2 [D7]
and see if the php 7.2 tests will pass. **UPDATE** php 7.2 only one fail, see issue below.
I have opened a new issue for that (combining the two patches).
#2947772: Fully support PHP 7.2 in Drupal 7
Comment #12
graham leach commentedHello,
In my experience, this error is the result of insufficiently "defensive" programming.
It occurs when PHP is asked to process something that lacks a *countable* property because what it is being presented with is NULL.
Objects that are NULL do not have a countable property, which is the nature of the error/notice given.
In previous versions of PHP, the [notice] error was not issued.
But, as the quality of PHP improved, the [notice] warning was added somewhere in PHP 7.
Here's an example of what would trigger that error:
Unfortunately, if the above function is passed a NULL array, a [notice] will be issued regarding the countable property.
To avoid this, implement "defensive" programming akin to what is being done these days to validate form input (i.e. assume the worst) to "sanitize" it:
Also, for those who might not know, using "&$elements" passes a reference to the variable as it exists in memory, not a copy of it. This is indicated by the "&" character.
https://www.php.net/manual/en/language.references.pass.php
For the purposes of this explanation you can ignore the "&" character in the function definition and simply consider it as "$elements".
I have written a little paper on this aspect/shortcoming of Drupal Core. If you are interested to learn more, contact me.
Comment #13
avpaderno