Drezard Posted March 7, 2008 Share Posted March 7, 2008 Im getting this error: Parse error: syntax error, unexpected T_NEW in C:\xampp\htdocs\input.class.php on line 17 Heres the code for input.class.php: <?php require_once('database.class.php'); class input { private $database = new database; function input () { $this->database->moderator(); } } ?> heres the code for database.class.php: <?php class database { // declare a few public variables private $database_host; private $database_username; private $database_password; private $database_database; private $database_connection; // connect to the database function connect() { $this->database_connection = mysql_connect($this->database_host, $this->database_username, $this->database_password); mysql_select_db($this->database_database, $this->database_connection); } // set up the database server constants function database () { $this->database_host = 'localhost'; $this->database_database = 'alias'; } // set up a moderator user, priveleges: SELECT, INSERT, UPDATE, DELETE // this user is used in the end-user app for anything more then just SELECT privelege job function moderator () { $this->database_username = 'moderator'; $this->database_password = '******'; $this->connect(); } // set up a basic user, priveleges: SELECT // this user is used in the end-user app to do any SELECT jobs no more priveleges function user () { $this->database_username = 'user'; $this->database_password = '******'; $this->connect(); } // set up a maintance user, priveleges: SELECT, INSERT, UPDATE, DELETE // this user is used for cron jobs and other maintance tasks // DANGER: should not be used in any end-user part of the app function maintance () { $this->database_username = 'maintance'; $this->database_password = '******'; $this->connect(); } } ?> Whats wrong with this? Daniel Quote Link to comment Share on other sites More sharing options...
KrisNz Posted March 7, 2008 Share Posted March 7, 2008 You need to create the object in your constructor, i.e <?php require_once('database.class.php'); class input { private $database; //database object function input () { $this->database = new database(); $this->database->moderator(); } } ?> Quote Link to comment Share on other sites More sharing options...
numan82 Posted March 9, 2008 Share Posted March 9, 2008 hi, but the most important thing you are missing here is, Which I got at glance is whenever you declear the object of any class it should be like this $obj= new ClassName();//Class Name if you notice your code carefully you are not using parenthesis with your class name when creating object so private $database = new database;//wrong approach try this private $database = new database();//correct one. try out this! I am sure the parse error for new line will be eliminated. Thanks! Keep Smile Numan Khan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.