Then you need to make sure its defined.
An easy way to do this if you where using an mvc approach, or even just a simple bit of OOP would be to store all your variables within an object (View), this way you can easily make sure to return something.
<?php
class View
{
private $_data = array();
public function __set($name, $value)
{
$this->_data[$name] = $value;
}
public function __get($name)
{
if (isset($this->_data[$name])) {
return $this->_data[$name];
}
return NULL;
}
public function render($template)
{
ob_start();
include $template;
echo ob_get_clean();
}
}
Now, lets say you have the a template: example.php
<html>
<head>
<title><?php echo $this->title; ?></title>
</head>
<body>
<p><?php echo $this->foo; ?></p>
</body>
</html>
Even if the variable 'foo' isn't defined you wont get any error because it will just return NULL.
<?php
$v = new View;
$v->title = 'this is an example';
$v->render('example.php');
Of course this idea can be extended quite a bit but it's a start.