Page 1 of 1

Chain function calls?

Posted: Sun Mar 19, 2006 2:40 pm
by alex.barylski
It doesn't appear PHP4 supports this?

So I have to break away from my zeal for OOP and use data member chaning instead or am I missing something here?

Is there a way you can indeed chain function calls?

Thanks :)

Posted: Sun Mar 19, 2006 2:46 pm
by John Cartwright
Not allowed in php4, althought here is a workaround http://blog.casey-sweat.us/?p=38

Posted: Sun Mar 19, 2006 2:48 pm
by alex.barylski
Jcart wrote:Not allowed in php4, althought here is a workaround http://blog.casey-sweat.us/?p=38
I just googled it seconds before your post :P

So, PHP 5 supports function call chaining?

Cheers :)

Posted: Sun Mar 19, 2006 2:49 pm
by John Cartwright
So, PHP 5 supports function call chaining?
yup :)

Re: Chain function calls?

Posted: Sun Mar 19, 2006 4:27 pm
by Roja
Hockey wrote:So I have to break away from my zeal for OOP and use data member chaning instead or am I missing something here?
MUAHAHAHhahaha...
Hockey wrote:So, PHP 5 supports function call chaining?
Aww, ruined the fun. Pout.

Re: Chain function calls?

Posted: Sun Mar 19, 2006 5:23 pm
by alex.barylski
Roja wrote:
Hockey wrote:So I have to break away from my zeal for OOP and use data member chaning instead or am I missing something here?
MUAHAHAHhahaha...
Hockey wrote:So, PHP 5 supports function call chaining?
Aww, ruined the fun. Pout.
I'm a hardened OOP guy...for years I had private, public and protected access control then I started developing in PHP...

I'm really no keene/kean(e)?? on allowing access to data members, never mind force the technique by making it mandatory :)

I really don't like that ad hoc hack either...thats what I call spaghetti code...

Who introduced eval() anyways??? :P

Dynamic programming is best left out of imperative languages and best left for artificial intelligence or viruses. IMHO anyways :)

I'll stick with my mutators/accessors and just use the old trusty re-assignment approach instead of function chaining :)

When most of the world upgrades to PHP5 (why is it taking so long) I'll then possibly re-implement using chaining...

Stupid hosting companies :(

Posted: Sun Mar 19, 2006 5:24 pm
by alex.barylski
Wow...I used alot of smiley's in that last message

Posted: Sun Mar 19, 2006 7:08 pm
by Christopher
I'm not sure that chaining is such a good idea anyway -- except maybe for accessors. I think it seems cooler than it is. There is an assumption that every method returns a valid object. I still prefer to explicitly assign to vars.

Posted: Sun Mar 19, 2006 8:01 pm
by alex.barylski
arborint wrote:I'm not sure that chaining is such a good idea anyway -- except maybe for accessors. I think it seems cooler than it is. There is an assumption that every method returns a valid object. I still prefer to explicitly assign to vars.
As do I, however sometimes, IMHO, syntactically it's cleaner and makes obviouse sense without the clutter of a few more lines...

Kinda like initializing multiple variables to zero using:

Code: Select all

$var1 = $var2 = $var3 = $var4 = 0;
As opposed to:

Code: Select all

$var1 = 0;
$var2 = 0;
$var3 = 0;
$var4 = 0;
When working with a DOM I often use chaining because the model is rendered visually for you and you can also use raw HTML to develop a mental picture of what exactly the chain commands are doing.

In cases where I'm working with a verbose class hierarchy (such as a framework) I tend to use seperate variables just for clarity sake.

Cheers :)

Posted: Sun Mar 19, 2006 10:35 pm
by Christopher
Yep, yep, yep and yep.

Posted: Sun Mar 19, 2006 11:27 pm
by alex.barylski
arborint wrote:Yep, yep, yep and yep.
Yup :P