Hi there,
As I pointed out in one of discussions, turning on E_STRICT error reporting in php.ini is one of the first things I do for each larger project, I develop. This sometimes might be painful for the developer, I mean - especially all those reminders about unset variable, which become fatal errors and are halting application execution, when E_STRICT is on.
The easiest way to avoid them is of course to use isset function. But what about rendering a views, where you are passing some variables as arrays? What to do there in this error reporting mode? I would like to ask you, what in your opinion is best approach for this problem.
Suppose we have:
$this->render('index', array
(
'scripts_array'=>$scripts_array,
'flash'=>$flash,
));
and suppose one or both of this additional variables might not be set in some situations as, for example they are result of if condition check or for loop.
I know two approaches for solving this problem. One approach is to force setting of variable before passing it to view. Like this:
$scripts_array = (isset($scripts_array)) ? $scripts_array : '';
$flash = (isset($flash)) ? $flash : '';
$this->render('index', array
(
'scripts_array'=>$scripts_array,
'flash'=>$flash,
));
Second one is to use variable as array when passing stuff to view. Like this:
$array = (isset($scripts_array)) ? array($scripts_array) : array();
$array = (isset($flash)) ? array_merge($array, $flash) : $array;
$this->render('index', array($array));
Which approach is better in your opinion? Or maybe you know a third or fourth, even better solution?