faqts : Computers : Programming : Languages : PHP : kms : Classes

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

13 of 15 people (87%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Can I store an array of objects as an object variable?

Jul 13th, 2000 12:21
Ben Udall, Kyle Olsen,


Yes, it is possible to store an array of objects as an object variable.
However, there are some syntax quirks to take note of.
class client
{
    var $first_name;
    var $last_name;
    var $id;
}
class dept_info
{
    var $name;
    var $clients;
}
$cs_dept = new dept_info;
// Create a temporary client object
$cs_client = new client;
$cs_client->first_name = 'John';
$cs_client->last_name  = 'Doe';
$cs_client->id         = 12345;
// Set the array element to the temporary object
$cs_dept->clients[0] = $cs_client;