Connecting Tech Pros Worldwide Forums | Help | Site Map

Indirect object access in php4

Zioth
Guest
 
Posts: n/a
#1: Feb 8 '06
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_OPERATOR

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
Guest
 
Posts: n/a
#2: Feb 8 '06

re: Indirect object access in php4


On 8 Feb 2006 10:54:40 -0800, "Zioth" <google@zioth.com> 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_OPERATOR
>
>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.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Zioth
Guest
 
Posts: n/a
#3: Feb 9 '06

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.

Closed Thread