What does ++$this->position?

The question was asked: 6 years 9 months ago   views: 15
0
class ' myIterator implements Iterator {
 private $position = 0;
 private $array = array(
"firstelement",
"secondelement",
"lastelement"
);

 public function __construct() {
 $this->position = 0;
}

 function next() {
var_dump(__METHOD__);
++$this->position;
}

}

$it = new myIterator;

I can not understand what kind of design ++$this->position;

Asked: 06-09-2012 в 10:52:43
![alt text][1] [1]: i.imgur.com/ceREP.png - 06-09-2012 в 11:10:51
But it is not clear why this is the case, ++$a, rather than the more usual $a++ - 06-09-2012 в 16:53:05

Answers   2

0

This means that incrementarse property position, i.e. transition to the next element. A more understandable form looks like this:

++($this->position);

or even so:

++$position;
Answered: 06-09-2012 в 11:08:39
and it is not nravitsa record $this->position++? - 06-09-2012 в 11:10:14
Code clarity is one of its main qualities. Entry ++$position - simply nowhere, but then it's better. - 06-09-2012 в 11:13:10
thank you very much. - 06-09-2012 в 11:19:10
0

This operation increases the operand by 1. In this case, the position variable of your class is incremented. The operation is called a Prefix increment, to read about it Moree here:

Operators increment and decrement operators in PHP.

Answered: 06-09-2012 в 11:11:24