www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Invoking functions in returned objects, a neater method?

  1. #1
    Join Date
    May 2006
    Location
    Prague, Czech Republic
    Posts
    66

    resolved [RESOLVED] Invoking functions in returned objects, a neater method?

    I am trying to invoke a function of an object that is returned by running another function.

    Here is my code:

    PHP 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:

    PHP Code:
    $this->title $this->OM->searchChildren('title')[0]->collateCharacterData(); 
    Any suggestions?!

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    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.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,609
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    May 2006
    Location
    Prague, Czech Republic
    Posts
    66
    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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles