0

I have a code structure like this:

class clsName{

    public $data = [];

    public function menu1(){
        $this->data['active']['menu1'] = 'a_p_t';
    }

    public function menu2(){
        $this->data['active']['menu2'] = 'a_p_t';
    }

    public function makeMenu(){
        return "<ul>
                    <li class='".$this->data['active']['menu1']."'>menu1</li>
                    <li class='".$this->data['active']['menu2']."'>menu2</li>
                </ul>";
    }
}

In reality, there are 20 items in the menu .. so, I always get 19 undefined warnings. Because always only one of them is activated. So, any idea how can I avoid those warnings?

An ugly way is to define all array-items (all keys of menu) inside each method, but I'm looking for a better appraoch.

stack
  • 10,280
  • 19
  • 65
  • 117
  • @NikleshRaut Very good .. thank you – stack Sep 28 '19 at 11:07
  • @NikleshRaut Noted that apparently without parentheses it won't work correctly. So it would be written this way: `
  • menu1
  • ` – stack Sep 28 '19 at 11:15