OBJECT()
Contents
Purpose
Function to create an anonymous object
Syntax
OBJECT([<property value> | <property name> => <property value> [,...]])
See Also
ACLASS(), ADDPROPERTY(), AMEMBERS(), COMPOBJ(), CREATEOBJECT(), DEFINE CLASS, DISPLAY CLASSES, DODEFAULT(), FOREACH, LIST CLASSES, LOADOBJECT(), NEWOBJECT(), PRINT_HTML(), PRINT_JSON(), PRINT_R(), PRINT_XML(), REMOVEPROPERTY(), REQUIRE_ONCE(), SAVEOBJECT(), SQL SELECT, WITH, ARRAY()
Description
The OBJECT() function is used to create an anonymous object. Properties are declared in a comma-separated list. Properties can be values only, <property value>, in which case they are given an automatically generated name: 00000001, 00000002 ... Property names can be specified using the <property name> => <property value> syntax. The OBJECT() function can also be included within the <property value> definition. The OBJECT() function returns an object.
The difference between array() and object() is that array() creates a dynamic array and object() creates an anonymous object that has “factory methods”:
addproperty(name, expression) removeproperty(name) clone() list() equals( anotherobject )
Example
customer = object("custname" => "A Buyer Ltd.", ; "currentorder" => object("ord_id" => "00001", "ord_date" => date(),"ord_total" => 1599,; "orderitems" => object("10 reams A4 paper","500 business cards",; "500 black ballpoint pens"))) display memory Memory Variables: ------------------------ private(2): CUSTOMER Object (refptr OBJECT, refcnt 1) .CUSTNAME Character 'A Buyer Ltd.' .CURRENTORDER Object (refptr OBJECT, refcnt 0) .ORD_ID Character '00001' .ORD_DATE Date 12/21/2012 .ORD_TOTAL Numeric 1599 (1599.000000000) .ORDERITEMS Object (refptr OBJECT, refcnt 0) [1] Character '10 reams A4 paper' [2] Character '500 business cards' [3] Character '500 black ballpoint pens' ** Total of ** 10 variables defined and 864 bytes use ** Total of ** 10 variables defined and 864 bytes used.