I'm having a small problem with a variable in one of my PHP scripts. The variable is $isSubMenu
. It gets set using a function that runs recursively called createNavigationMenu. However, even though I have set it, the interpreter keeps telling me that the variable is undefined. I really don't know what's going on because I've checked several times and I'm sure that it IS defined.
Does this have anything to do with the fact that the function is being called recursively?
Any input would be greatly appreciated.
Thanks for your help in advance.
Dodzi
P.S. How do you turn on language specific formatting now that they've changed the tags?
<?php
private function convertToListItem( $heading, $path = "", $isHeading = false, $isSubMenu )
{
//safety check
if( is_null($heading) )
{
return;
}
//initializations
$listItem = $heading;
$itemClass = $isHeading ? "nav_heading" : "nav_list_item";
//format heading
$listItem = $this->underscoresToSpaces( basename( $listItem, ".php" ) );
if( !empty($path) )
{
//add hyperlink
$subMenuClass = $isSubMenu ? "nav_sub_menu" : "";
$path = $this->getRelativePath( $this->currentFilePath, $path );
$listItem = "<a href='$path' class='$subMenuClass'>$listItem</a>";
//first new item only
$isSubMenu = false;
}
$listItem = "<li class='$itemClass'>$listItem";
if( !$isHeading )
{
$listItem .= "</li>";
}
return $listItem;
}
private function createNavigationMenu( $menuTree, $isSubMenu = false )
{
$treeSize = count( $menuTree );
$menuAsString = "";
for( $i = 0; $i < $treeSize; $i++ )
{
$heading = key( $menuTree );
$path = current( $menuTree );
//menu heading
if ( strpos( $heading, SITE_NAVIGATION_SUB_MENU_SUFFIX ) === false )
{
$menuAsString = sprintf(
"%s%s",
$menuAsString,
$this->convertToListItem( $heading, null, true, $isSubMenu )
);
}
//is new sub menu
if( is_array( $path ) )
{
$menuAsString .= $this->createNavigationMenu( $path, true );
}
else //create menu
{
$menuAsString = sprintf(
"%s%s",
$menuAsString,
$this->createListForHeading( $path )
);
}
$menuAsString .= "</li>" . PHP_EOL;
next( $menuTree );
}
//wrap in nav tags
$menuAsString = sprintf(
"<ul>%s</ul>" . PHP_EOL,
$menuAsString
);
return $menuAsString;
}