Project

General

Profile

Actions

Task #66322

closed

Use static:: instead of self::

Added by Markus Hölzle over 9 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Code Cleanup
Target version:
-
Start date:
2015-04-08
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Sprint Focus:

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?

Actions #1

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.

Actions #2

Updated by Riccardo De Contardi almost 9 years ago

  • Category set to Code Cleanup
Actions #3

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.

Actions

Also available in: Atom PDF