Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting Parse error: syntax error, unexpected T_NEW [closed]

Tags:

php

I have two classes memberdao and member class .I am creating an object of memberdao class inside member class .here is my code

require_once('/../dao/memberdao.class.php');

class Member
{
public $objMemberDao= new MemberDao(); 

}

but it gives an error Parse error: syntax error, unexpected T_NEW in C:\xampp\htdocs\membership\lib\member.class.php on line 9. I am new in php so please help

like image 757
Biswajit Avatar asked Apr 04 '13 09:04

Biswajit


People also ask

What is an unexpected syntax error?

Syntax Error – This error is caused by an error in the PHP structure when a character is missing or added that shouldn't be there. Unexpected – This means the code is missing a character and PHP reaches the end of the file without finding what it's looking for.

What is a PHP parse error?

Parse Error (Syntax) Parse errors are caused by misused or missing symbols in a syntax. The compiler catches the error and terminates the script. Parse errors are caused by: Unclosed brackets or quotes. Missing or extra semicolons or parentheses.

How do I fix parse error syntax error unexpected?

A parse error: syntax error, unexpected appears when the PHP interpreter detects a missing element. Most of the time, it is caused by a missing curly bracket “}”. To solve this, it will require you to scan the entire file to find the source of the error.


1 Answers

you cannot initialize new objects there. you must do it in the __construct function;

require_once('/../dao/memberdao.class.php');

class Member
{
  public $objMemberDao; 

  public function __construct()
  {
    $this->objMemberDao= new MemberDao(); 
  }
}
like image 116
Mircea Soaica Avatar answered Nov 09 '22 17:11

Mircea Soaica