1

The following notice and warning occurs after var_dump has excecuted correctly; i.e. var_dump($params) works, but these errors occur thereafter.

I found that using public function __construct($params='') in Models_Index class will cause ommition of these errors from occuring, but I'm not sure why they occur, or why this helps.

Warning: Missing argument 1 for Models_Index::__construct()

Notice: Undefined variable: params in models_index class on line 7

class Router {
  public function __construct(){
    $cont = new Controller('Passing params');
  }
} 
new Router;

class Controller extends Core_Controller {
  public function __construct($params) {  
    $model = $this->model("Models_Index", $params);
  }
}

class Core_Controller {
  protected function model($model, $params) {
    $model = new Models_Index($params);
    return new $model;
  }
}

class Models_Index extends Core_Model {
  public function __construct($params) {
    var_dump($params); // line 7
  }
}
7
  • your Controller class has no constructor, so exactly what are you expecting PHP to do with the $params you're trying to pass into it with new Controller($params)? Commented Oct 8, 2014 at 18:40
  • Is $params a value when it is sent to the Models_Index constructor? Commented Oct 8, 2014 at 18:41
  • @MarcB, yes it does. Commented Oct 8, 2014 at 18:41
  • @jack: woops. sorry. going cross-eyed here. Commented Oct 8, 2014 at 18:43
  • @MarcB No worries, haha. Commented Oct 8, 2014 at 18:44

1 Answer 1

3

The problem is you return new $model:

return new $model;

.. which is equal to

return new Models_Index();
Sign up to request clarification or add additional context in comments.

3 Comments

Not quite, it would be equal to: new Models_Index($params), so i was returning new new Models_Index($params) - which caused the error. You put me on the right track though, so +1.
Ok, my mistake, but I figuered it didnt make sense.
Actually, @msfoster is correct that it equals new Models_Index(). If it were triggering new Models_Index($params), you would just be seeing the output twice without errors. This is why it warns a parameter is missing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.