Nested function calls - specifically to class structures

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ebertjb
Forum Newbie
Posts: 12
Joined: Wed Sep 11, 2002 9:46 am

Nested function calls - specifically to class structures

Post by ebertjb »

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.*/

Code: Select all

$eventRec = GetRecord("Event");
        $eventfld =& $eventRec->GetField("ID");
        $eventfld->SetValue(5);
Is there a way that I could do this (below is pseudocode)

Code: Select all

$eventRec = GetRecord("Event");
        // Merge the 2 lines into one;
        $eventRec->GetField("ID")->SetValue(5);
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???
Post Reply