Using the ::class constant instead of string literals

In the topic https://review.typo3.org/#/q/topic:use-class-constant I change (almost) all places where a class name is given with a string literal to use \Actual\Class\Name::class instead. I’ll follow the currently pushed changes with adjustments to the documentation and the packages that make up Neos (right now only the Flow packages have been adjusted).

I want to point out why this makes sense, so it hopefully becomes best practice:

  • auto-completion in your IDE
  • detection of errors in your IDE (misspelling, undefined class)
  • shorter names through use of use are possible
  • when refactoring, it’s clear a class is referenced

It would be nice if everyone adjusted to this and patches for Flow > 3.0 and Neos > 2.0 (because that constant has been added in PHP 5.5) would use that in the future…

1 Like

And while writing this, I realised there is one open issue: Following our CGL this should be ::CLASS instead of ::class… I’ll push new changes. :slight_smile:

Are you sure about this one? according to PHP: The Basics - Manual it is not a constant but a keyword

1 Like

Awesome. I tried to find the documentation, but failed. Awesome. Have to admit ::class is much nicer than ::CLASS.

1 Like