PHP方法返回此,对性能有影响吗? [关闭]

How does it affect performance by making sure that all my setters return $this? To allow for chain calls similar to jQuery coding standards.

E.g:

public function setEnabled(){
    $_enabled = true;
    return $this;
}

I found this other question with no reference to the performance side, surley there is a negative

Objects are passed by reference unless you specifically clone them (in php 5 anyway). I don't see any performance impact by doing this.

No significant performance impact. Objects are not cloned.

NO the another question answer everything, in your code sample your Function will always true, and could be chain if you want

PHP return null; is the same as return; which is the same as not returning anything at all. Either way, something is being returned, it may as well be the objects reference to itself.

Most every line of code comes with a performance hit. But is that not the point of writing that line of code

Your question is very vague and depends on a few factors. The size object being returned, how it is being received, and the calculations made on $this before it is being returned.

Usually there is no issues with returning $this but it is all a question of judgement. If $this contains a huge data array, you can figure it will use more memory and processing time than in your example.