On 6 Jan 2005 09:41:24 -0800,
ed*@greenberg.org wrote:
This works:
$b = $a->method1();
$c = $b->method2();
I'd like to get this all on one expression, something like:
$c = ${$a->method1()}->method2();
which doesn't work.
Is there any way to avoid actually creating and then using the $b
object?
andyh@server:~/public_html$ cat test.php
<?php
class B {
function method2()
{
return 'x';
}
}
class A {
function method1()
{
return new B();
}
}
$a = new A();
$c = $a->method1()->method2();
print $c;
print "\n";
?>
andyh@server:~/public_html$ php -q test.php
x
andyh@server:~/public_html$ php -v
PHP 5.0.3 (cli) (built: Dec 22 2004 02:41:40)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool