But does passing the entire object back and forth hinder performance? Depending on how much data and/or other objects held within $this, I’d imagine this technique might be coder friendly, but could hurt processing time.
I don’t believe passing the object back in method chaining back requires any more processing time then instantiating and then calling each method separately. Method chaining is complied into PHP so, chances that it take any more or less time then parsing the sequential code could be debated. But IMHO the code reads better using chaining than the more traditional PHP class and method ways.
Yeah, I don’t think there really is any difference in performance. Even if there were, it would be negligible and it would be outweighed by the benefits that come with having cleaner, more readable code.
This is true for PHP 5 to an extent, it may be by reference or an identifier, either way, it isn’t the actual object itself, it is a pointer to the object. Thus in my opinion, your daisy chaining is acceptable by all means of performance. The only time it would not be, is if you were forcing the object itself to be returned instead of the identifier or the reference pointer which isn’t default behavior.
One of the key-points of PHP 5 OOP that is often mentioned is that “objects are passed by references by default”. This is not completely true. This section rectifies that general thought using some examples.
A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP 5, an object variable doesn’t contain the object itself as value anymore. It only contains an object identifier which allows object accessors to find the actual object. When an object is sent by argument, returned or assigned to another variable, the different variables are not aliases: they hold a copy of the identifier, which points to the same object.
I hope not many people are using a version of php below 5.3, but it’s hard to say. Thankfully if you are using 5 or higher you are okay with how objects are passed around in PHP except for oddball cases as described in the Source link I provided.