1

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;?

Community
  • 1
  • 1
Julio María Meca Hansen
  • 1,303
  • 1
  • 17
  • 37
  • 4
    `var`? What is this? 2001? Also: http://stackoverflow.com/questions/455109/var-for-a-class-in-php?rq=1 – PeeHaa Oct 05 '12 at 17:47
  • @PeeHaa The problem are the zillions of "PHP tutorials" left on the web we can't make go away. – Michael Berkowski Oct 05 '12 at 17:48
  • @MichaelBerkowski Don't get me started about all that crap out there. One of these days I'm going to do a whois on all of them and pay them a visit. – PeeHaa Oct 05 '12 at 17:49
  • 2
    @PeeHaa I expect most should fall pretty easily to the SQL injection holes they promote in their sample code! – Michael Berkowski Oct 05 '12 at 17:50

1 Answers1

6

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

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592