Bug #88756

TypoScript – Symfony Expressions: request.getQueryParams() should do an "is defined" validation

Added by Hagen Gebauer 3 months ago. Updated about 1 month ago.

Status:
Rejected
Priority:
Should have
Assignee:
Category:
TypoScript
Target version:
-
Start date:
2019-07-15
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
Tags:
symfony, expression,CodingNight
Complexity:
Is Regression:
Sprint Focus:

Description

[request.getQueryParams()['tx_news_pi1']['news'] > 0]
do something
[END]

This is working well – as long as the query parameter exists. If it doesn’t, the following error message will be written into the log file:
... {"expression":"request.getQueryParams()['tx_news_pi1']['news'] > 0","exception":"RuntimeException: Unable to get an item on a non-array. in ...

I have tried changing the condition as follows, hoping that it would be interpreted as “is defined” – but the results are exactly the same:
[request.getQueryParams()['tx_news_pi1']['news']]

In my view there should be an automated PHP isset() validation for such conditions. Or at least a way to actively check for is defined as you can do in Symfony’s Twig templating engine for example. I couldn’t find a similar way for TypoScript – please enlighten me if I just missed it.


Related issues

Related to TYPO3 Core - Task #89176: Provide better way to traverse array in TS conditions Under Review 2019-09-14

History

#1 Updated by Frank Naegler 3 months ago

  • Status changed from New to Accepted
  • Assignee set to Frank Naegler

#2 Updated by Gerrit Code Review 3 months ago

  • Status changed from Accepted 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 https://review.typo3.org/c/Packages/TYPO3.CMS/+/61315

#3 Updated by Susanne Moog 2 months ago

  • Tags changed from symfony, expression to symfony, expression,CodingNight

#4 Updated by Gerrit Code Review 2 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61315

#5 Updated by Frank Naegler 2 months ago

  • Status changed from Under Review to Rejected

If you build your condition like this you don't have an issue:

[request.getQueryParams()['tx_news_pi1'] && request.getQueryParams()['tx_news_pi1']['news'] > 0]

The first part will create a notice, but an exception will not occur.

#6 Updated by Hagen Gebauer about 2 months ago

Frank Naegler wrote:

If you build your condition like this you don't have an issue:

[...]

The first part will create a notice, but an exception will not occur.

Thank you! This is working indeed – but to me it isn’t quite logical: why doesn’t the way I tried ([request.getQueryParams()['tx_news_pi1']['news']]) work as well, when with dropping the ['news'] a proper is_defined is being performed? Besides I wasn’t able to find documentation on that behaviour and the returned exception anywhere.

I still believe the is_defined validation should be done automatically, considering Typoscript should be simplified compared to a proper programming language.

#7 Updated by Markus Klein about 1 month ago

  • Related to Task #89176: Provide better way to traverse array in TS conditions added

#8 Updated by Markus Klein about 1 month ago

Find my take on this in #89176

Also available in: Atom PDF