Chain function calls?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Chain function calls?

Post 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 :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Not allowed in php4, althought here is a workaround http://blog.casey-sweat.us/?p=38
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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 :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

So, PHP 5 supports function call chaining?
yup :)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Chain function calls?

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Chain function calls?

Post 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 :(
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Wow...I used alot of smiley's in that last message
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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 :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Yep, yep, yep and yep.
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

arborint wrote:Yep, yep, yep and yep.
Yup :P
Post Reply