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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

justas.raudonius created an issue. See original summary.

justas.raudonius’s picture

Eric_A’s picture

Status: Active » Reviewed & tested by the community

Yeah, 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."

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed b90bd58 and pushed to 8.8.x. Thanks!

  • larowlan committed b90bd58 on 8.8.x
    Issue #3078839 by justas.raudonius: Incorrect return type declaration...

Status: Fixed » Closed (fixed)

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