[TYPO3-mvc] Determine Concrete Object Type

Philipp Wrann philippwrann at gmail.com
Mon May 5 08:14:28 CEST 2014


All variants are completely okay to use...

use a getter for the object-type record field
use instanceof construct
use get_class

i would use the first possibility and address the different values as class constants in the superclass, that way it is very readable, you can use a switch construct and if used very often it is for sure faster that using get_class or any other object-related function. If you set the record-field as integer in your model you only compare integers, that would look like

switch ($object->getType()) {
case Object::TYPE_ONE:
// do something
break;
case Object::TYPE_TWO:
// do something else
break;
default:
// do some fallback that will -most likely- never be the case, but if some recordtype is distinct in development this can assure some compat.
break;
}


More information about the TYPO3-project-typo3v4mvc mailing list