Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The $links
variable in theme_links()
can be NULL
which is not countable.
Comment | File | Size | Author |
---|---|---|---|
fix-count-on-non-countable-theme_links.patch | 409 bytes | jacob.embree | |
Comments
Comment #2
sjerdoSeems like the default value for links in drupal_common_theme() is NULL.
LGTM +1
We should check if we missed some other default values.
Comment #3
sjerdoComment #4
sjerdoFound 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().
Comment #5
Jorrit CreditAttribution: Jorrit at nCode for DOM Digital Online Media GmbH commentedThe 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()
.Comment #6
bkosborneThe 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?
Comment #7
Jorrit CreditAttribution: Jorrit at nCode for DOM Digital Online Media GmbH commentedYou're right, I hadn't realized that patch #7 was superseded in that issue.
Comment #8
PolHi,
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 useif (array() === $links)
.What do you think ?
Comment #9
PolComment #10
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commentedI would still use
!empty()
. The code below is to act if the variable is not empty. I think what you meant wasif (array() !== $links)
(not an empty array), but what if$links
isNULL
, not even an array? In that case the code below should not run.Comment #11
PolHi,
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.Comment #12
Fabianx CreditAttribution: Fabianx as a volunteer commentedi 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
Comment #13
Fabianx CreditAttribution: Fabianx as a volunteer commentedCan we open a follow-up for $tasks in theme_task_list, please?
Also is any of that a problem in Drupal 8 [with Twig]?
Comment #14
PolFixing commit credit.
Comment #15
joseph.olstadthis didn't make it into 7.60, bumping to 7.61
Comment #17
Fabianx CreditAttribution: Fabianx as a volunteer commentedPushed to 7.x. Thanks!
Comment #19
joseph.olstadThis is fixed, thanks again everyone!
Removing the pending commit tag (it was already committed).