I need to instance 2 or more classes on top of my controller class, so I can use them with $this->filter
or $this->logger_instance
inside any method of my controller class. Right now it is not letting me, I get an error. (I do not want to extend the class if possible.) Is it okay to instance in construct if it is possible.
Parse error: syntax error, unexpected T_NEW in controller.php
(I am in the process of transferring my coding habits from procedural to OOP so I am really bad at it.)
class ID_Controller
{
public $input;
public $register_attempt = 2;
public $maximum_attempts = 3;
public $log_data_attempts = 2;
public $query_log_file_path;
public $sql_filtering = true;
public $xss_filtering = true;
public $sql_register_attempt = 3;
public $xss_register_attempt = 6;
public $filter = new ID_Algorithm;
public $logger_instance = new ID_Logger;
function __construct()
{
}
}
Why not try initializing these classes through the __construct()
method?
/*
If the two classes are located in seperate files, be sure to require them:
*/
require("ID_Algorithm Page");
require("ID_Lodder Page");
class ID_Controller {
/* previous lines here */
/*
Comment out the next two lines and initiate them within the construct class
*/
// public $filer = new ID_Algorithm;
// public $logger_instance;
public $filer;
public $logger_instance
public function __construct(){
$this->filter = new ID_Algorithm;
$this->logger_instance = new ID_Logger;
}
}
Then when calling:
$Class = new ID_Controller();
this will set the necessary internal pointers correctly.