Page 1 of 1
PHP objects:: method chaining efficiency!
Posted: Thu Dec 18, 2008 4:46 am
by jaoudestudios
How efficient is method chaining...
Is there a greater overhead using method chaining because the object is returned in each method?
Can static methods be chained?
Code: Select all
object::method1()::method2()::method3()
Re: PHP objects:: method chaining efficiency!
Posted: Thu Dec 18, 2008 6:58 am
by Chris Corbyn
jaoudestudios wrote:How efficient is method chaining...
Is there a greater overhead using method chaining because the object is returned in each method?
The overhead would be minimal, or possibly non-existent. The parser shouldn't have to do much work to make method chaining work, it's just evaluating a set of expressions (method calls) from left to right in the normal scanning routine a scanner makes. I don't know about the internals of PHP specifically though.
Can static methods be chained?
Code: Select all
object::method1()::method2()::method3()
No. You can only make static calls to a class and you can't return a class.
Re: PHP objects:: method chaining efficiency!
Posted: Thu Dec 18, 2008 7:53 am
by jaoudestudios
Cheers

Re: PHP objects:: method chaining efficiency!
Posted: Fri Dec 19, 2008 5:30 am
by Jenk
You already can chain?
Code: Select all
$object->method()->method2()->method3()->etc();
Re: PHP objects:: method chaining efficiency!
Posted: Fri Dec 19, 2008 8:51 am
by Chris Corbyn
I think we know that bit. The question was about performance (or at least, my answer was)

Re: PHP objects:: method chaining efficiency!
Posted: Fri Dec 19, 2008 9:31 am
by jaoudestudios
It was about performance, dont know what Jenk is smoking!?!

Re: PHP objects:: method chaining efficiency!
Posted: Fri Dec 19, 2008 9:35 am
by josh
Technically couldn't you return a singleton to do static chaining? Don't see the purpose, but technically?
Re: PHP objects:: method chaining efficiency!
Posted: Fri Dec 19, 2008 4:25 pm
by Chris Corbyn
It's not really static but yeah it'd have a similar effect.
Re: PHP objects:: method chaining efficiency!
Posted: Fri Dec 19, 2008 4:44 pm
by josh
Yeah it would be pretty much retarded but I was just thinking out of the box

Re: PHP objects:: method chaining efficiency!
Posted: Mon Dec 22, 2008 5:27 am
by Jenk
jaoudestudios wrote:It was about performance, dont know what Jenk is smoking!?!

Well if you want to play that card
What are you smoking to think it would be any different from returning objects other than $this?

Re: PHP objects:: method chaining efficiency!
Posted: Mon Dec 22, 2008 6:58 am
by jaoudestudios
Well, in my defense, I thought because $this is being returned it would have a larger overhead.
Re: PHP objects:: method chaining efficiency!
Posted: Mon Dec 22, 2008 10:02 am
by klee
I was wonder if any one could help me. I am creating a page that allows user to insert date into mysql via check boxes. The code allow the information be inserted but does not return check values from the data on the refresh. Does any have any methods that may work?
Re: PHP objects:: method chaining efficiency!
Posted: Mon Dec 22, 2008 10:05 am
by John Cartwright
klee wrote:I was wonder if any one could help me. I am creating a page that allows user to insert date into mysql via check boxes. The code allow the information be inserted but does not return check values from the data on the refresh. Does any have any methods that may work?
We will be glad to help you. However, de-railing a thread is not the way to ask for help. Kindly create your own thread and ask your question(s) there.