在PHP中的另一个类中创建类对象作为数据成员 [英] Create class object as data member in another class in PHP
本文介绍了在PHP中的另一个类中创建类对象作为数据成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我必须在另一个类中创建一个类对象作为数据成员。如何在PHP中实现这一点。
例如
class TableModel {
public $ totalRecords;
public $ pageNumber;
//更多会员&功能。
}
class SearchModel {
public $ ID;
//更多会员&功能。
//想要在这里创建TableModel类的对象....
}
什么我试过了:
我试过几种方式,比如
public $ tableoptions = TableModel();
public $ tableoptions = new TableModel;
$ tableoptions = new TableModel();
&更多方法。
解决方案
totalRecords;
public
pageNumber;
//更多会员&功能。
}
class SearchModel {
public
ID;
//更多会员&功能。
//想要在这里创建TableModel类的对象....
}
什么我试过了:
我试过几种方式,比如
公共
Hi All,
I have to create one class object as data member in another class. How to achieve that in PHP.
eg
class TableModel { public $totalRecords; public $pageNumber; // More members & functions. }
class SearchModel { public $id; // More members & functions. // Want to create object of TableModel class here.... }
What I have tried:
I tried several ways like
public $tableoptions = TableModel(); public $tableoptions = new TableModel; $tableoptions = new TableModel();
& many more ways.
解决方案
totalRecords; public
pageNumber; // More members & functions. }
class SearchModel { public
id; // More members & functions. // Want to create object of TableModel class here.... }
What I have tried:
I tried several ways like
public
这篇关于在PHP中的另一个类中创建类对象作为数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文