Click to See Complete Forum and Search --> : [RESOLVED] Invoking functions in returned objects, a neater method?


SlappyTheFish
11-01-2006, 08:23 AM
I am trying to invoke a function of an object that is returned by running another function.

Here is my code:


$object = $this->OM->searchChildren('title');
$this->title = $object[0]->collateCharacterData();


This works, but is there a neater way to do this in one line? I have tried the following, but it doesn't work:


$this->title = $this->OM->searchChildren('title')[0]->collateCharacterData();


Any suggestions?!

chazzy
11-01-2006, 06:46 PM
no, that won't work.

you can have searchChildren return a "ListOf" type of object, and use something like

$this->title=$this->OM->searchChildren('title').get(0)->collateCharacterData();

But note that this makes your code very hard to read.

NogDog
11-01-2006, 08:58 PM
Yeah, I don't think you gain anything by making it a one-liner, unless you're trying to obfuscate things so no one else can modify the code. :)

SlappyTheFish
11-02-2006, 06:27 AM
Thanks for the replies - I think you're right though, it does make it rather hard to read. I was really just trying to represent the relational hierarchy in the code but I don't think it really works!