My method or function recurseMenu (in: UssdNode.php) normally contains the list of menus (WHICH I LOOK TO DISPLAY) contained in the variable $title=$node->getTitle():
function recurseMenu($items,$bufferLimit) {
        $objectString="<strong>". $this->getTitle() . "</strong>" . PHP_EOL;
        $lastMenu=false;
        var_dump($items);           //DEBUG "items"
        if(count($items)>0) {
            for ($i = $this->index; $i <= $bufferLimit; $i++) {
                if ($items[$i]) {
                    $item = $items[$i];
                    $num = $i + 1;
                    // get node by name
                    $userSessions = $_SESSION['userSessions'];
                    $currUserSession = $userSessions[$this->address];
                    $node = $currUserSession->getNode($item);
                    $title = $node->getTitle();
                    $objectString .= PHP_EOL . $num . '. ' . $title;
                }
            }
        } else {
            $objectString=$objectString.PHP_EOL . 'NO DATA AVAILABLE, TRY AGAIN LATER';
        }
        $lastMenu=$bufferLimit==count($items);
        $objectString=$objectString . PHP_EOL . PHP_EOL . "<strong>0. Exit</strong>";
        if($this->getParent() != '0'){
            $objectString=$objectString . PHP_EOL . "<strong>#. Back</strong>";
        }
        if($lastMenu===false){
            $rem=count($items)-$this->index;
            $objectString=$objectString . PHP_EOL . "<strong>99. Next (".$rem.")</strong>";
        }
        return $objectString;
    }
The getNode method of the UssdTree.php file:
function getNode($name){
        $node=$this->treeMenu[$name];
        return $node;
    }
And when I try the debug of $this->recurseMenu($items,$bufferLimit) in my toString method or function which displays the list of $title as strings:
function toString(){
        $objectString='';
        $items=$this->children;
        $bufferLimit=(count($items)==0)?1:$this->getBufferLimit()+1;
 
        echo "<pre>";
        print_r($this->recurseMenu($items,$bufferLimit));
        echo "</pre>";
 
        do{
            $bufferLimit-=1;
            $objectString=$this->recurseMenu($items,$bufferLimit);
        }while(strlen($objectString>160));
        $this->index=$bufferLimit;
        return $objectString;
    }
So, the problem is that nothing is displayed. And I get the following error:
- Line 86 of the error I get and put below is from the UssdNode.phpfile which contains the statement bytrueof the variableif ($items[$i])in therecurseMenumethod below:
Notice: Undefined offset: 4 in C:\laragon\www\ussd\ussdmenu-server-php\UssdNode.php on line 86
When I the debug of var_dump($items); at the line 3 in my recurseMenu method or function above, I get this return:
array(4) {
[0]=>
string(5) "umeme"
[1]=>
string(4) "nwsc"
[2]=>
string(5) "paytv"
[3]=>
string(10) "paycurrent"
}
And when I edit $bufferLimit variable by removing the addition +1 at $this->getBufferLimit()+1 in the declaration of the variable $bufferLimit=(count($items)==0)?1:$this->getBufferLimit()+1; of the toString function, the menus are displayed fine but it creates another lag when pressing or issuing the request for the 99. Next key.
How to correctly display the list of menus represented by the variable $title=$node->getTitle(); in the recurseMenu method below ?
Help me fix this error.
