Issue Task Closed

#98519Uninitialized properties in DebuggerUtility

Mario Lubenka 10/04/22, 12:02 updated 12/06/22, 21:41

Description

DebuggerUtility:var_dump is commonly used to debug PHP classes.
In the latest PHP versions it is recommended to use typed properties in PHP classes.
Hardening PHP classes via typed properties ensures type safety at runtime.

class MyClass {
  protected array $myArray;
  protected \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe;

  __constructor(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe) {
    $this->tsfe = $tsfe;
  }
};

Typed properties have to states: initialized and uninitialized. All typed properties are uninitialized until a value is assigned.
That’s usually the case in constructors, but it may also happen at runtime.

Objects with uninitialized typed properties throw an exception when passed into DebuggerUtility::var_dump:

$test = new class {
  protected \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe;
};
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($test);

error.png

Expected behaviour

As the DebuggerUtility is intended for development purposes, uninitialized variables should not break the website.
Instead, a label “uninitialized” should be attached to the property so the developer can do the intended debugging but still knows about uninitialized variables.

suggested_fix.png

Reviews 2