[TYPO3-50-general] TypoScript syntax: Array indexes

Robert Lemke robert at typo3.org
Thu Jul 19 10:36:30 CEST 2007

Hi folks,

I've been thinking for some time now about an issue with the syntax  
of array indexes in TypoScript.
Consider the following example:

    myArrayObject = ContentArray

    myArrayObject.10 = Text
    myArrayObject.10.value = "Hello "

    myArrayObject.20 = Text
    myArrayObject.20.value = "world!"

"myArrayObject" is a regular TypoScript content object which can be  
rendered. It probably has no properties itself but it does have Array  
capabilities, ie. it has sub objects. There are two sub objects,  
namely "10" and "20". When the ContentArray is rendered, it just  
aggregates the content of all sub objects.

So far so good. But not for the parser and not if we don't use  
numerical indexes. Consider this:

    myObject = Template
    myObject.file = xyz
    myObject.subParts.footer = Text

"file" is a property of the "Template" object and so is "subParts".  
However, subParts has Array behaviour (although it's no object) and  
footer is the index in that array. Now, from the parser's view this  
looks very ambiguous: How can it know (without knowing the internals  
of an object) that subParts behaves like an array?

A cleaner approach would be to distinguish between properties and  
array indexes by using a different syntax:

    myArrayObject = ContentArray

    myArrayObject[10] = Text
    myArrayObject[10].value = "Hello "

    myArrayObject[20] = Text
    myArrayObject[20].value = "world!"


    myObject = Template
    myObject.file = xyz
    myObject.subParts["footer"] = Text

To me that looks intuitive enough and the parser is especially happy  
because he now gets a hint.

But there's even more trouble at the horizon: TypoScript allows for  
implicitly defining array objects, on the fly:

    anotherObject.sub1.sub2.sub3 = ContentArray
    anotherObject.sub1.sub2.sub3.1 = Text
    anotherObject.sub1.sub2.sub3.1.value = "Yawn"

This definition implies that "anotherObject", "sub1" and "sub2"  
should behave like an array, but they haven't been defined anywhere!  
We could agree on that if objects are created _implicitly_, they  
don't become true "ContentArray" objects but are just dumb PHP arrays  
which don't have any object behaviour, they only exist for containing  
sub arrays or objects. This compromise would read like this with the  
new syntax:

    anotherObject.sub1.sub2.sub3 = ContentArray
    anotherObject.sub1.sub2.sub3[1] = Text
    anotherObject.sub1.sub2.sub3[1].value = "Yawn"

So, what's your opinion? Can you live with that new syntax? Is it  
intuitive enough? Or do you see another loophole out of the parser  


More information about the TYPO3-project-5_0-general mailing list