I can not seem to find any documents stating if anonymous functions in templates are a good idea when templating HTML with PHP. I have the following code for example:
<html><body>
<?
$listMethod = function($items)
{
?>
<ul>
<?foreach ($items as $item):?>
<li><?=$item?></li>
<?endforeach;?>
</ul>
<?
};
?>
<?=$listMethod(array('1','2','3'))?>
<p> AND </p>
<?=$listMethod(array('a','b','c'))?>
</body></html>
Is this a good or bad way to create templates in PHP?
Bad bad way , it will be realy hard to debug them, edit, find, … . You could include a template_functions.php file at the top of you’re template and store all template related functions/helpers there .
Edit
Allso do not use short tags if you’re into conding standards , most hosting companyes will allow them ( short tags ) but a few whont so you’ll have problems .