title: php Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION on construct
body: <p>hey guys was hoping you could help me out..</p>
  
  <p>just to let u know in advance, im a relatively new php coder, doing a practice project, and came across this problem and ive spent like an hour of rechecking and googling but just cant figure out whats causing it</p>
  
  <p>error: Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\forum\classes\ClassUser.php on line 7</p>
  
  <p>the segment of the code causing the problem:</p>
  
  <pre><code>include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
  Class User{
  
  
  __construct($u,$p){ //this is line 7
  
      $user=$u;
      if(strlen($p)&gt;30|| empty($p) || !preg_match('/[^a-zA-Z0-9]/i',$p)){
      $password=0;
  
      }
      else{
      $password=hash_hmac('md5',$p,KEY);
  
      }
  
  }
  </code></pre>
  
  <p>oh and since im new to php, incase im doing something which i should not be, please to recommend.. thanks in advance.</p>
  
  <p>note:ive removed the php tags  since they seemed to be messing with the formatting of this post :/</p>
  
  <p>note2: im also getting another notice
  Notice: Use of undefined constant KEY - assumed 'KEY' in C:\wamp\www\forum\classes\general.inc on line 20</p>
  
  <p>but im assuming thats more of a warning than an error... but just adding incase it has something to do with the error</p>
  
  <p>general.inc:</p>
  
  <pre><code>//error definations
  define("ERROR_FIELD_EMPTY","Error! All required fields not filled");
  define("ERROR_INVALID_SIGNIN","Error! Username/password do not match!");
  define("ERROR_GENERAL_INPUT", "Error! Invalid input given");
  define("ERROR_SQL_CONNECT","Error! Could not connect to sql database");
  
  
  //field sizes
  define("PASSWORD_LENGTH",12);
  define("USERNAME_LENGTH",30);
  
  //sql server details
  define("SQL_SERVER_NAME","localhost");
  define("SQL_SERVER_USERNAME","root");
  define("SQL_SERVER_PASSWORD","");
  define("SQL_SERVER_DATABASE","forums");
  
  define(KEY,"key");
  
  
  function __autoload($className){
      require_once($_SERVER["DOCUMENT_ROOT"]."forum/classes/Class$className.php");
  
  }
  </code></pre>
  
  <p>ClassUser.php</p>
  
  <pre><code>  include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
      Class User{
  
  
      __construct($u,$p){
  
          $user=$u;
          if(strlen($p)&gt;30|| empty($p) || !preg_match('/[^a-zA-Z0-9]/i',$p)){
          $password=0;
  
          }
          else{
          $password=hash_hmac('md5',$p,KEY);
  
          }
  
      }
  
      public function validate(){
          if(strlen($user)&gt;30|| empty($user) || preg_match('/[^a-zA-Z0-9]/i',$password==0 )){
          throw new Exception(ERROR_GENERAL_INPUT);
  
  
  
          }
          $user=mysql_real_escape_string($user);
          return true;
  
      }
  
      public function insert(){
         // this-&gt;validate();
  
          $conn= mysqli_connect(SQL_SERVER_NAME,SQL_SERVER_USERNAME,SQL_SERVER_PASSWORD,SQL_SERVER_DATABASE);
  
  
          if(empty($conn)){
          throw new Exception(ERROR_SQL_CONNECT);
          }
  
          $query="INSERT into USERS VALUES ($user,$password)";
          $conn-&gt;query($query);
  
  
  
      }
  
      private $user;
      private $password;
  
      };
  </code></pre>
  
  <p>NewUser.php</p>
  
  <pre><code> include $_SERVER["DOCUMENT_ROOT"]."forum/classes/general.inc";
  
  
  
  
      try{
      $user = new User($_POST['UserName'],$_POST['Password']);
      $user-&gt;insert();
      }
  
      catch(Exception $Error){
      echo $Error-&gt;getMessage();
  
  
      }
  </code></pre>