php 获取解析错误:语法错误,意外的 T_NEW
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15806981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getting Parse error: syntax error, unexpected T_NEW
提问by Biswajit
I have two classes memberdao and member class .I am creating an object of memberdao class inside member class .here is my code
我有两个类 memberdao 和成员类。我正在成员类中创建 memberdao 类的对象。这是我的代码
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
但它给出了一个错误解析错误:语法错误,第 9 行 C:\xampp\htdocs\membership\lib\member.class.php 中的意外 T_NEW。我是 php 新手,所以请帮忙
回答by Mircea Soaica
you cannot initialize new objects there. you must do it in the __construct function;
你不能在那里初始化新对象。您必须在 __construct 函数中执行此操作;
require_once('/../dao/memberdao.class.php');
class Member
{
public $objMemberDao;
public function __construct()
{
$this->objMemberDao= new MemberDao();
}
}
回答by Tapas Pal
create object of MemberDao class into the constructor of Member class
在 Member 类的构造函数中创建 MemberDao 类的对象
class Member
{
public $objMemberDao;
public function __construct()
{
$this->objMemberDao= new MemberDao();
}
}