The $links variable in theme_links() can be NULL which is not countable.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jacob.embree created an issue. See original summary.

sjerdo’s picture

Seems like the default value for links in drupal_common_theme() is NULL.

LGTM +1

We should check if we missed some other default values.

sjerdo’s picture

Issue summary: View changes
sjerdo’s picture

Issue tags: +Drupal 7.60 target

Found another:
'tasks' in theme_task_list() defaults to NULL in drupal_common_theme().

I guess the default value should be changed to an empty array or a check should be add in theme_task_list().

Jorrit’s picture

The changes made by #2885610: [PHP 7.2] Avoid count() calls on uncountable variables in theme_table() were different from the changes proposed here. I think in order to maintain consistency, the change should be:

$links = (array)$variables['links'];

instead of changing count to !empty.

A similar change is possible in theme_task_list().

bkosborne’s picture

Status: Needs review » Reviewed & tested by the community

The changes made by #2885610: [PHP 7.2] Avoid count() calls on uncountable variables in theme_table() were different from the changes proposed here. I think in order to maintain consistency, the change should be:

The patch from that issue uses the same !empty() method, not array casting. What are you referring to?

For the theme_task_list issue, did you see this problem occur or is just something you noticed when looking at the theme function?

Jorrit’s picture

You're right, I hadn't realized that patch #7 was superseded in that issue.

Pol’s picture

Status: Reviewed & tested by the community » Active

Hi,

Before committing this, I would wait for this patch first: #2996519: PHP 7.2 compatibility - make sure some variables are arrays in theme_links(). and then, instead of using !empty(), I would then use
if (array() === $links).

What do you think ?

Pol’s picture

jacob.embree’s picture

I would still use !empty(). The code below is to act if the variable is not empty. I think what you meant was if (array() !== $links) (not an empty array), but what if $links is NULL, not even an array? In that case the code below should not run.

Pol’s picture

Hi,

I think what you meant was if (array() !== $links) (not an empty array), but what if $links is NULL, not even an array?

This is precisely why I said that we should wait for the patch in #2996519: PHP 7.2 compatibility - make sure some variables are arrays in theme_links(). to make sure that $links is always an array.

Fabianx’s picture

Status: Active » Reviewed & tested by the community
Issue tags: +Pending Drupal 7 commit

i agree that even with the changes in the other issue it is still more common to our normal 'way-of-things' to test !empty() instead of using count().

So back to RTBC

Fabianx’s picture

Can we open a follow-up for $tasks in theme_task_list, please?

Also is any of that a problem in Drupal 8 [with Twig]?

Pol’s picture

Fixing commit credit.

joseph.olstad’s picture

Issue tags: -Drupal 7.60 target +Drupal 7.61 target

this didn't make it into 7.60, bumping to 7.61

  • Fabianx committed 1664b8b on 7.x
    Issue #2988184 by jacob.embree, Pol, sjerdo, Jorrit: Fix call to count...
Fabianx’s picture

Status: Reviewed & tested by the community » Fixed

Pushed to 7.x. Thanks!

Status: Fixed » Closed (fixed)

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

joseph.olstad’s picture

Issue tags: -Pending Drupal 7 commit

This is fixed, thanks again everyone!

Removing the pending commit tag (it was already committed).