Click here to Skip to main content
15,891,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 20-Jan-17 3:20am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900