symphonycms/symphony-2 — Issue #984: Parameter type validation in all Widget class methods
Author: vlad-ghita
Created: 2011-12-23 12:48:02+00:00
State: open

I just found myself chasing ghosts with XMLElement class:

[:0] GenericErrorHandler::handler();
[...]\symphony\lib\toolkit\class.xmlelement.php:592] strlen();
[...]\symphony\lib\toolkit\class.xmlelement.php:608] XMLElement->generate();
[...]\symphony\lib\toolkit\class.xmlelement.php:608] XMLElement->generate();
[...]\symphony\lib\toolkit\class.xmlelement.php:608] XMLElement->generate();
[...]\symphony\lib\toolkit\class.xmlelement.php:608] XMLElement->generate();
[...]\symphony\lib\toolkit\class.htmlpage.php:89] XMLElement->generate();
[...]\symphony\lib\toolkit\class.administrationpage.php:352] HTMLPage->generate();
[...]\symphony\lib\core\class.administration.php:397] AdministrationPage->generate();
[...]\index.php:25] Administration->display();

The problem actually was with a XMLElement generated with `Widget::input(....)` who received to [`$value` parameter an array instead of string](https://github.com/symphonycms/symphony-2/blob/master/symphony/lib/toolkit/class.widget.php#L62).

What do you say about type checking in all Widget::xxxx methods? Best practice et all.

e.g.

if( is_string($value) ) $value = '';

or something. This way the developer will notice what XMLElement has problems, instead of the above error which says nothing in the end. Lucky I had a debugger ...