Nested function calls - specifically to class structures
Posted: Mon Nov 11, 2002 9:55 am
I love using classes but feel like I am limited if I have to write multiple lines to do one process - does PHP allow multiple calls per line for classes? Here is an example:
/*FYI - Function GetRecord() returns object type Record, and GetField() is a function within object Record that returns an object of type Field. SetValue is a function of type Field that sets the value of that field.*/
Is there a way that I could do this (below is pseudocode)
In this second scenario, the first function call returns an object of type Field, which then would set the value to 5 (and do other processing).
My constructor of class record already allocates space for each of the fields, so there really isnt a need to re-allocate for variable $eventfld as an instance of the field - all allocation could stay within the class if I could just reference it that way.
but it seems (through my testing of this) that PHP only allows single function calls to its class structure. Am I wrong?
any ideas???
/*FYI - Function GetRecord() returns object type Record, and GetField() is a function within object Record that returns an object of type Field. SetValue is a function of type Field that sets the value of that field.*/
Code: Select all
$eventRec = GetRecord("Event");
$eventfld =& $eventRec->GetField("ID");
$eventfld->SetValue(5);Code: Select all
$eventRec = GetRecord("Event");
// Merge the 2 lines into one;
$eventRec->GetField("ID")->SetValue(5);My constructor of class record already allocates space for each of the fields, so there really isnt a need to re-allocate for variable $eventfld as an instance of the field - all allocation could stay within the class if I could just reference it that way.
but it seems (through my testing of this) that PHP only allows single function calls to its class structure. Am I wrong?
any ideas???