I am testing my code, and realizing that I have a bigger issue…
What I want to happen is this…
In “index.php” I have this line in my php section which comes before my HTML section…
$sectionName = getSectionName($dbc, $slug);
And then a few lines later I have…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- HTML Metadata -->
<title><?php echo (isset ($sectionName) ? $sectionName : 'EMPTY') ?> Section</title>
If getSectionName() successfully finds the “Section Name” for the “Section Slug” in the URL, then I want it displayed in <title> and also below in my HTML code (not shown here).
If getSectionName() cannot find the “Section Name” for the “Section Slug” in the URL, then I want…
1.) To call this function so I can log the error…
// Log Function Error.
logError($dbc, $resultsCode, $errorPage);
2.) I want to return something like the Zero-Length String, so my HTML page still loads and doesn’t crash.
function getSectionName($dbc, $slug){
$sectionName="";
// if, (buts and maybes) {
// do your stuff here
// else chuck silent errors
}
// then no matter what happens:
return $sectionName;
}
You could develop that idea further if you wanted:
function getSectionName($dbc, $slug, $default = ''){
$sectionName= $default;
// do your stuff here
// else chuck silent errors
// then no matter what:
return $sectionName;
}
This would leave you open to using it like:
echo sectionName($foo,$bar);
// OR adding something slightly more helpful
echo sectionName($foo,$bar, $siteName);
The cost is that you have an extra [optional] argument going into your function, some might find that ugly.
The way I fixed it was simply removing exit() in my logError() function, so that after that function is called, control just continues in the parent code and then I can keep my return “” in the ELSE branch of my code.