473,387 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

$class->method()->method()

edg
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?

Thanks,
</edg>
Ed Greenberg
San Jose CA USA

Jul 17 '05 #1
4 2103
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?

Thanks,
</edg>
Ed Greenberg
San Jose CA USA


If I'm not mistaking you'll be needing PHP5 to use that syntax...
In PHP5 $a->method1()->method2() works, in PHP4 it doesn't as far as I know.

Rutger
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #2
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.


Use $c = $a->method1()->method2;

You'll need PHP 5 for this syntax.

Regards,
Matthias
Jul 17 '05 #3
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
Jul 17 '05 #4
edg
Thanks for all the responses.

I suppose I should have posted that I have to use PHP4 :(
Any ideas for the more traditional approach?

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Edvard Majakari | last post by:
Hi, I just found py.test and converted a large unit test module to py.test format (which is actually almost-no-format-at-all, but I won't get there now). Having 348 test cases in the module and...
8
by: Nick | last post by:
I have the following code: var obj = {a:0, b:1, ...} function f() {...} obj.f = f // This will make a instance method? How to make a Class method for the class of obj? Or what's the...
10
by: lkrubner | last post by:
I killed last night and a good chunk of today trying to figure out this one particular attempt to get a class and initialize it. My code is using a class method called getObject to include() a file...
4
by: Amy Matlock | last post by:
Hi all: How does the hardware work if you invoke a BASE::METHOD() on a DERIVED class member? Do you still hit the v-table dynamically at run time? Suppose you have a derived class method, but...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
1
by: question | last post by:
I want to know incase there is any performance difference or overhead in calling a base class method and a derived class method. Basically I am talking about simple method that is not overridden...
2
by: Sylvain Ferriol | last post by:
hello can you explain why python does not see difference between instance method and class method, having the same name example .... def f(self): .... print('instance method')...
0
by: alwayssmiling | last post by:
hi, I created an abstract class. In that a method which returns same class object, like predifned class, system.drawing.image a = system.drawing.image.fromfile(filename) this...
13
by: Hussein B | last post by:
Hi, I'm familiar with static method concept, but what is the class method? how it does differ from static method? when to use it? -- class M: def method(cls, x): pass method =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.