1

I'm getting an error:

Undefined offset: 1

This is the code. It gives the error on this line:

list ($controller,$method) = explode("@", $match['target']);

Full code:

<?php
include(__DIR__ . "/bootstrap/start.php");

include(__DIR__ . "/routes.php");

$match = $router->match();

list ($controller,$method) = explode("@", $match['target']);


if (is_callable(array($controller, $method))) {
  $object = new $controller();
  call_user_func_array(array($object, $method), array($match['params']));
} else {
  echo "Cannot find $controller -> $method";
  exit();
}

Screenshot:

enter image description here

Blue
  • 22,608
  • 7
  • 62
  • 92
JuNk
  • 11
  • 4
  • This means that `$match[0]` has no `@` symbol. – u_mulder Aug 11 '16 at 11:45
  • Hi @u_mulder I edited to topic seems i uploaded the wrong code this is the orginal. – JuNk Aug 11 '16 at 11:57
  • Welcome to Stackoverflow! I've gone ahead and edited your code a bit to fit more with the style that most users are accustomed to here. Errors are recommended to be put into block quotes, as they are usually the most important and should deserve attention. Also, try to stray away from "Thanks", and tag lines as they clutter the post. Get straight to the point, ask your question, and show your research, and you'll be a stack overflow master in no time! – Blue Aug 11 '16 at 12:02
  • Have you checked `$match['target']`? – u_mulder Aug 11 '16 at 12:44
  • `explode("@", $match['target'])` does not produce enough array elements to satisfy `list ($controller,$method)`. You can do `$explode = explode("@", $match['target']);` followed by some `isset()` checking like this: `if(isset($explode[0])){$controller = $explode[0];} if(isset($explode[1])){$method = $explode[1];}` – MonkeyZeus Aug 11 '16 at 13:21

0 Answers0