0

When i try to define a variable in __construct it still gives me an error of an undefined varbile. could you help?

    <?php



    class view {

public $model;


function    __construct($url,$root,$model,$common_model,$common_view,$alt_root,$it_selected,$hr_selected,$finance_selected) {

    $this->it_selected = $it_selected;
    $this->hr_selected = $hr_selected;
    $this->finance_selected = $finance_selected;
    $this->url = $url;
    $this->model = $model;
    $this->common_model = $common_model;
    $this->common_view = $common_view;
    $this->root = $root;
    $this->alt_root = $alt_root;


    $this->loader();


}

i still recieve it_selected, hr_selected & finance_selected are not defined.

Jamie Harding
  • 31
  • 1
  • 6
  • You have to define them in your PHP class like you defined `$model`. – Holt Apr 24 '14 at 09:01
  • In other word under `public $model`, add `private $it_selected;` or public, do that for all the var u using in the construct – Rob Apr 24 '14 at 09:05
  • Please show us all the error messages, in their entirety. – Sverri M. Olsen Apr 24 '14 at 09:06
  • Also, are you sure it does not have something to do with the variables that are passed *into* the constructor, when instantiating the class? For example, `new view($a, $b, $c, ...)`, are all the `$a`, `$b`, `$c`, `...` variables defined? – Sverri M. Olsen Apr 24 '14 at 09:09
  • 1
    Do you call the __construct with all 9 parameters? The closest I can come to your error is calling __construct() with only 6 parameters, which leads to 3 warnings and 3 notices. – Duroth Apr 24 '14 at 09:09
  • these are the error codes i was getting before i changed the code. undefined variable: it_selected in /var/www/vhosts/talent.co.uk/httpdocs/intranet/view/the_helpdesk.php line 457 undefined variable: finance_selected in /var/www/vhosts/talent.co.uk/httpdocs/intranet/view/the_helpdesk.php line 457 undefined variable: hr_selected in /var/www/vhosts/talent.co.uk/httpdocs/intranet/view/the_helpdesk.php line 457 – Jamie Harding Apr 24 '14 at 09:21
  • Can you show us the line 457 of the file `the_helpdesk.php`? – Sal00m Apr 24 '14 at 09:22
  • They are all on the same line. It is probably when you instantiate the class. Please show us line 457. – Sverri M. Olsen Apr 24 '14 at 09:24
  • @JamieSterling That is not the line that is causing this. – Sverri M. Olsen Apr 24 '14 at 09:25
  • Current ViewHelpdesk: – Jamie Harding Apr 24 '14 at 09:30
  • this is the line that is for the error code. – Jamie Harding Apr 24 '14 at 09:39
  • @JamieSterling Okay... that did not help us much. Can you account for where `$it_selected`, `$hr_selected` and `$finance_selected` are defined? Also, it would help us a lot if you showed us *all the relevant code*. The snippets you have shown us are not enough for us to get the whole picture. – Sverri M. Olsen Apr 24 '14 at 09:52
  • i cannot add the whole code into a page but here is the .php file http://www.mediafire.com/view/4pa1edxtrtqkdk8/the_helpdesk.php – Jamie Harding Apr 24 '14 at 10:05

0 Answers0