Say I have this class:
class A {
private
$var_a,
$var_b;
public function do_something(){
$local_var_a = $this->var_a;
// ... Lots of use of $local_var_a
$this->var_a = $local_var_a;
}
public function do_something_else(){
// ... Lots of use of $this->var_a
}
}
Which function is the ‘better’ one to use and why?
Better is a very ambiguous term. Related to coding in most cases it usually means
The difference in memory usage and performance are very tiny, and I’m no friend of micro-optimization (unless I have too much time at my hands), so I would answer for those two points: it doesn’t matter.
For usability and readability I prefer
function do_something_else(), this makes it way easier for me and someone else to understand how the code works, how it can be tested and documented.