Task #66322
closedUse static:: instead of self::
0%
Description
Hi there,
is there a reason why TYPO3 uses "self::" to access static methods? For more flexibility it would be nice if TYPO3 uses "static::" (so you can extend the classes).
For example in the fluid translation view helper:
class TranslateViewHelper extends AbstractViewHelper implements CompilableInterface { public function render(...) { return self::renderStatic(...); } static public function renderStatic(...) { ... } } class MyPrefixedTranslateViewHelper extends TranslateViewHelper { public function render(...) { // this function has nothing new, it's just there to call our own static function return self::renderStatic(...); } static public function renderStatic(...) { ... } }
If you just want to overwrite the static function "renderStatic", you also have to overwrite the non-static function "render". If "static::" would be used in the function "render", you just have to overwrite the function "renderStatic".
This looks this way:
class TranslateViewHelper extends AbstractViewHelper implements CompilableInterface { public function render(...) { return static::renderStatic(...); } static public function renderStatic(...) { ... } } class MyPrefixedTranslateViewHelper extends TranslateViewHelper { static public function renderStatic(...) { ... } }
What do you think?
Updated by Stephan Großberndt over 9 years ago
http://php.net/manual/de/language.oop5.late-static-bindings.php introduced with PHP 5.3, thus possible with TYPO3 CMS 7 and TYPO3 CMS 6.2.
I think for most pieces of code that are touched occurrences of self are replaced with static, but there are still several left.
Updated by Christian Kuhn over 7 years ago
- Status changed from New to Closed
closing this general coding issue for now. if you have specific areas where static instead of self is especially useful, please push according patches.