[Flow] getters for option arrays (Surf)

Helmut Hummel helmut.hummel at typo3.org
Sun Nov 2 16:50:29 CET 2014


Hi Martin!

On 02.11.14 14:47, Martin Kutschker wrote:

> public function getOption($key) {
>     return $this->options[$key];
> }
>
> If you ask for an option that has not been set, PHP will issue a notice
> which in turn be changed by Flow into an exception. I know I can fiddle
> around with the PHP configs (and Flow configs?), but shouldn't be the
> code changed to avoid this?

 From what I know from the Surf code, this is on purpose!

> A  simple solution:
>
> public function getOption($key) {
>     return isset ($this->options[$key]) ? $this->options[$key] : NULL;
> }

Instead, the code that evaluates the options should decide if an option 
is required or not.

If an option is optional, the code (e.g. in a task) must call 
->hasOption() first and act accordingly.

It is also possible to use ->hasOption() for required options to give 
reasonable error messages instead of having an exception thrown because 
of a notice.

But in any case this is better to throw an exepction instead of 
proceeding and accidently using a NULL value which could lead to 
unexpected results.

Kind regards,
Helmut

-- 
Helmut Hummel
Release Manager TYPO3 6.0
TYPO3 CMS Active Contributor, TYPO3 Security Team Member

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the Flow mailing list