Indirect object access in php4

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Zioth

    #1

    Indirect object access in php4

    class A {
    function Get() {return $this;}
    }
    $obj = new A();


    In php5, the following statement is valid:
    $x = $obj->Get()->Get();

    In php4, I get the following error:
    parse error, unexpected T_OBJECT_OPERAT OR

    I know I can do this:
    $x = $obj->Get();
    $y = $x->Get();

    but I'd rather not. Is there a simple, one-line way to do indirect
    object references in php4?

    And yes, I know my example is silly. My real problem is for more
    complicated cases, where multiple classes are involved.

  • Andy Hassall

    #2
    Re: Indirect object access in php4

    On 8 Feb 2006 10:54:40 -0800, "Zioth" <google@zioth.c om> wrote:
    [color=blue]
    >class A {
    > function Get() {return $this;}
    >}
    >$obj = new A();
    >
    >
    >In php5, the following statement is valid:
    >$x = $obj->Get()->Get();
    >
    >In php4, I get the following error:
    >parse error, unexpected T_OBJECT_OPERAT OR
    >
    >I know I can do this:
    >$x = $obj->Get();
    >$y = $x->Get();
    >
    >but I'd rather not. Is there a simple, one-line way to do indirect
    >object references in php4?[/color]

    Nope, AFAIK. You have to go to PHP5.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Zioth

      #3
      Re: Indirect object access in php4

      > >but I'd rather not. Is there a simple, one-line way to do indirect[color=blue][color=green]
      > >object references in php4?[/color]
      >
      > Nope, AFAIK. You have to go to PHP5.[/color]

      Not even some wierd trick, using typecasting and some form of brackets?
      In perl, there are always ways to get around this kind of problem using
      curly braces and typecasting.

      What a strange thing for them to omit from PHP4. It seems like a pretty
      basic thing for a parser to allow return values to be actionable. Oh
      well.

      Comment

      Working...