Project

General

Profile

Actions

Bug #61090

closed

Static access to Enumeration constants

Added by Mathias Brodala over 10 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Miscellaneous
Target version:
Start date:
2014-08-20
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.3
Tags:
Complexity:
easy
Is Regression:
No
Sprint Focus:

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:

  1. You have to rely on a __default being defined or have to pick an arbitrary value to create the instance
  2. 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


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #64971: Static access to enumeration constants requires instance onceClosedMathias Brodala2015-02-10

Actions
Actions

Also available in: Atom PDF