Issue Task Closed

#98091[T3DD22] Cleanup: Refactor and simplify array access

Tizian Schmidlin 08/05/22, 22:18 updated 07/09/24, 15:55

Description

The core is littered with “useless” statements, checking if a variable that maybe is not initialized is an array, like this:

if (is_array($var['key']) && is_array($var['key']['subKey']) {
    foreach ($var['key']['subKey'] as $v) {
        // ...
    }
}

This can, if the source of the variable is trustworthy, be simpified:

foreach ($var['key']['subKey'] ?? [] as $v) {
    // ...
}
Trustworthy sources might be:
  • signed functions or methods
  • methods that are not properly signed, but internally enforce the advocated return type
  • typoscript arrays with a dot-index (e.g. $conf['includeCss.']
Untrustworthy sources might be:
  • content based values
  • potentially faulty extension configurations
  • values from flexform fields
  • anything that might not come from a core extension

Reviews 1