Undefined Index error

I have two if statements in my __construct method and I keep getting an undefined index error. So if I try to fix it with isset() I get a message saying fatal error cannot use isset () on the result of an expression.

Here is my code

class Bootstrap{
	private $controller;
	private $action;
	private $request;

	public function __construct($request){
		$this->request = $request;
		
		if ($this->request['controller'] == ""){
			$this->controller = 'home';
		} else {
			$this->controller = $this->request['controller'];
		}
		if($this->request['action'] == ""){
			$this->action = 'index';
		} else {
			$this->action = $this->request['action'];
		}
	}

All help greatly appreciated.

you never test, whether $request actually has a ‘controller’ entry.

Could you give me some idea what you are speaking of how to test $request ?

if (isset($request['controller'])) { 
  ....
  }

will only execute the block if the array element actually exists.

Thank you very much solved my problem I will remember to test, whether $request actually has a ‘controller’ entry.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.