Bug #104793
closedFatal error when overwriting defaultViewObjectName
0%
Description
Only happens in current-main (since https://github.com/TYPO3/typo3/commit/c22b72cde6838f4a080a22bde25b9f3632337169).
Fatal error: Type of MyNamespace\Controller\MyController::$defaultViewObjectName must be ?string (as in class TYPO3\CMS\Extbase\Mvc\Controller\ActionController)
This error happens since https://review.typo3.org/c/Packages/TYPO3.CMS/+/85735/ changed string
to ?string
in https://review.typo3.org/c/Packages/TYPO3.CMS/+/85735/60/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php#97.
Updated by Oliver Hader 3 months ago
- Related to Feature #104773: Implement and use a core ViewFactoryInterface added
Updated by Christian Kuhn 2 months ago
- Related to Task #102632: Use strict types in extbase ActionController added
Updated by Christian Kuhn 2 months ago
- Related to Task #104770: Do not declare extbase defaultViewObjectName, set it added
Updated by Christian Kuhn 2 months ago ยท Edited
- Status changed from Accepted to Resolved
The property has been changed with #102632 in v13 once already, the patch only changed it a second time.
In general, when abstracts delivered by core monorepo contain properties, extensions should set values in __construct() if they need to change values.
This has been documented with https://review.typo3.org/c/Packages/TYPO3.CMS/+/81885/10/typo3/sysext/core/Documentation/Changelog/13.0/Breaking-102632-UseStrictTypesInExtbaseActionController.rst
This is what pre-patch #104770 did, now following this advise to be a good example.
Since the property type has been changed in v13, giving extensions a chance adopting to this by setting the value in __construct(), and the type has now been "just" changed a second time, I do not consider this breaking as it has been marked breaking in 13.0 including a proper upgrade path already.
As such, I tend to keep the property type as is.
Updated by Christian Kuhn 2 months ago
Note we should probably communicate this more clearly: When core delivers some abstract with properties, extensions should in general set values of such properties in __construct().
This is the only way to give core freedom to add or change types without triggering liskov contra/co-variant violations.
I'll add a mental note to add something to typo3 explained cgl / best practice section docs.