$total = 0 and var $total = 0. Which is the correct one?
Possible Duplicate:
What does PHP keyword 'var' do?
I know this can sound like a strange question, but it's something I can't get out of my head. I'm defining a class to handle invoice lines and their respective taxes and my current 'prototype' looks like this:
public function getRate() {
if (!empty($this->lines)) {
var $total = 0;
foreach ($this->lines as $line) {
$total += $line->subtotal;
}
return ['title' => $this->attributes['title'], 'value' => $this->attributes['value'], 'type' => $this->attributes['type'], 'total' => $total];
}
}
$total is just there to count the lines' total ammount (per tax rate, in this case), so in my thoughts, it has to be discarded once the function returns the array. The question is... which is more appropiate (as in more correct)? $total = 0;
or var $total = 0;
?
Note: The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning.
In any case, the variable is inside the function, not inside the class, so visibility doesn't apply anyway. Just remove the var