Bug #61090
closedStatic access to Enumeration constants
100%
Description
To get all available constants for a TYPO3\CMS\Core\Type\Enumeration
, one has to create an instance and call the getConstants()
method. This is weird for various purposes:
- You have to rely on a
__default
being defined or have to pick an arbitrary value to create the instance - The enumeration constants are stored statically anyways so one should not need an instance to get them.
Compare the current state:
$myEnum = new MyEnum(MyEnum::VALID_VALUE); print_r($myEnum->getConstants());
With the desired state:
print_r(MyEnum::getConstants());
With PHP 5.3 the get_called_class() function was introduced which can be used here. In fact it is already used in Enumeration::cast()
and it is beyond me why not here.
To fix this, the getConstants()
method can be made static which fortunately does not break instance invocation:
A property declared as static cannot be accessed with an instantiated class object (though a static method can).
Thus the first example above will continue to work.
Files
Updated by Gerrit Code Review about 10 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/32353
Updated by Gerrit Code Review about 10 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/32353
Updated by Gerrit Code Review about 10 years ago
Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/33244
Updated by Anonymous about 10 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset b15537d2c9a543f757ef46e6c6e0080129cfb42a.