Noticed this error coming up switching to PHP 7 this morning. Looks like the template function is assuming that variable $footer is an array when it's not.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bkosborne created an issue. See original summary.

bkosborne’s picture

Status: Active » Needs review
FileSize
1.57 KB

This just swaps all these count() calls with !empty() which will handle the case when the value is null.

Status: Needs review » Needs work

The last submitted patch, 2: php7-countable-2999011.patch, failed testing. View results

selfsimilar’s picture

Alternatively, you could cast all the variables that should be arrays to array at the top of the function. e.g.

function bootstrap_table($variables) {
  $header = (array) $variables['header'];
  $rows = (array) $variables['rows'];
  $footer = (array) $variables['footer'];
  $attributes = (array) $variables['attributes'];
  $caption = $variables['caption'];
  $colgroups = (array) $variables['colgroups'];
  $sticky = $variables['sticky'];
  $empty = $variables['empty'];
  $responsive = $variables['responsive'];


  // Etc.
}
markhalliwell’s picture

Status: Needs work » Reviewed & tested by the community
+++ b/templates/system/table.func.php
@@ -136,7 +136,7 @@ function bootstrap_table(array $variables) {
-  if (!count($rows) && $empty) {
+  if (!empty($rows) && $empty) {

This should not have ! in front of empty. I'll fix on commit.

  • markcarver committed 2d2d397 on 7.x-3.x authored by bkosborne
    Issue #2999011 by bkosborne, markcarver: PHP 7 - Warning: count():...
markhalliwell’s picture

Status: Reviewed & tested by the community » Fixed
bkosborne’s picture

Ah good catch, thanks!

bkosborne’s picture

Here's the updated patch, just so I can include it in a make file.

joseph.olstad’s picture

Thanks for the fix,
IMHO, this fix warrants a tagged release, wink wink nudge nudge.
Drupal core 7.60 will be released 'any day now' and sports support for php 7.2.x, would be nice to hit the ground running when it is released.

markhalliwell’s picture

Are there any other PHP7 issues that should likely be fixed before that? I really haven't worked with D7 and PHP7 together much (mainly due to the fact that most contrib breaks).

joseph.olstad’s picture

AFAIK that's the only php7.x patch needed for bootstrap. unless someone else finds something else?

I did a blitz this weekend on drupal.org.

Yesterday I fixed organic groups so that it passes on all versions, had just a small change to the og.test to make, very small change. Requires the latest 7.x-dev core. php 7.2.x (see tests all pass)
#3000030: og fix head tests for various versions of php

I released libraries 7.x-2.4 last week that now supports 7.1.x and php 7.2.x (see tests all pass)

My servers can run 7.1.x , 7.2.x , 7.0.x , 5.6.x , 5.5.x per vhost settings, so each site can have it's own versions. So lately I've been trying out 7.1.x and 7.2.x. I also worked on the core fixes for 7.2.x , 7.60 will be released 'anytime now' , who knows, I think Pol wants to put quite a bit more fixes and new features/improvements in it.

joseph.olstad’s picture

views now passes all php 7.1.x and php 7.2.x

https://www.drupal.org/node/38878/qa

ctools passes as well:
https://www.drupal.org/pift-ci-job/1069673

Status: Fixed » Closed (fixed)

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

kevineinarsson’s picture

FileSize
611 bytes

Found another case of a null-count() in the table template. Patched against 7.x-3.x. Should I open another issue for this Mark?

joseph.olstad’s picture

Hi kevineinarsson please open a new issue for this and paste a link here so we can find it easily (set it as a related issue or just paste a link to it) please and thanks

joseph.olstad’s picture

Thanks for the patch kevin
I've created a new issue for you and marked it as RTBC, your patch is good, let's push it in
#3012715-2: PHP 7.2.x compatibility - in the table template

sgourebi’s picture

I tried all patches above and nothing worked. So I tried @selfsimilar way and it works with php7.2. I created a patch for php7.2. You can try it.

joseph.olstad’s picture

@sgourebi , merci pour le patch!

selon la politique, au lieu de prolonger un vieux issue déjà fermé, on doit créé un autre
/ according to policy, create a new issue instead of prolonging a closed one.

le voici: /here it is
#3088940: php 7.2.x / php 7.3.x countable warning fix

murrumba’s picture

I spent hours trying to solve it and what it solved for me was to make the adjustment below:

function wetkit_bootstrap_table($variables) {
// $header = $variables['header'];
// $rows = $variables['rows'];
$header = is_array($variables['header']) ? $variables['header'] : [];
$rows = is_array($variables['rows']) ? $variables['rows'] : [];
$footer = is_array($variables['footer']) ? $variables['footer'] : [];
//$attributes = $variables['attributes'];
$attributes = is_array($variables['attributes']) ? $variables['attributes'] : [];
$caption = is_array($variables['caption']) ? $variables['caption'] : [];
$caption = $variables['caption'];
//$colgroups = $variables['colgroups'];
$colgroups = is_array($variables['colgroups']) ? $variables['colgroups'] : [];
$sticky = is_array($variables['sticky']) ? $variables['sticky'] : [] ;
$empty = is_array($variables['empty']) ? $variables['empty'] : [] ;
$responsive = is_array($variables['responsive']) ? $variables['responsive'] : [];