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.
Return type for function drupal_static is declared as array
, while it returns $default_value
which can actually be of mixed
type (NULL
, bool
, objects
, etc), when static variable is not yet present.
Due to this incorrect return type declaration, static code analysis tools give false positives.
Comment | File | Size | Author |
---|---|---|---|
#2 | 3078839-incorrect-return-type-declaration-for-function-drupal_static.patch | 523 bytes | justas.raudonius |
Comments
Comment #2
justas.raudonius CreditAttribution: justas.raudonius commentedComment #3
Eric_A CreditAttribution: Eric_A at Dutch Open Projects commentedYeah, a returned $default_value could be anything.
For
$my_static = &drupal_static(__FUNCTION__);
PHPStan currently barks: "Variable $my_static in isset() always exists and is not nullable."Comment #4
larowlanCommitted b90bd58 and pushed to 8.8.x. Thanks!