SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question $obj->getsandobject()->retrievedobjectsmethod() = unexpected T_OBJECT_OPERATOR

    The Summary says it all.

    I have an object (object A) of class A, it has a method (lets call it getObjectB()) that returns a ref to an object (object B) of class B. Object B has a get method for one of its attributes (getValueA()). I'm will be using PHP 4.x. Clearly this works:

    $refA = new ObjectA;

    $refGetter = $refA->getObjectB();

    echo($refGetter->getValueA());

    But this does not:

    $refA = new ObjectA;

    echo($refA->getObjectB()->getValueA());

    It comes back with 'unexpected T_OBJECT_OPERATOR' of course for the additional '->'. But is there are way around this? It doesn't seem to be encapsulation in parenthesis etc?

    Just interested if any gurus know the answer.

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From Mike Naberenzy's article on fluent interfaces:
    In PHP 4, it was not possible to do chaining, but one of the great new features of PHP 5 is that it supports directly deferencing objects returned by methods.
    If at all possible, you should upgrade to PHP5. If you can't, you're stuck without chaining.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Salem, OR
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then I'm stuck.

    Thanks for the clarification, best of luck.


Bookmarks

Posting Permissions

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