Increment on “__toString”
I am not sure what the title should be, but the code should explain it better: class Group { private $number = 20; public function __toString() { return "$this->number"; } } $number = new Group(); echo $number, PHP_EOL; echo ++ $number, PHP_EOL; echo PHP_EOL; $number = "20"; echo $number, PHP_EOL; echo ++ $number, PHP_EOL; echo PHP_EOL; $number = 20; echo $number, PHP_EOL; echo ++ $number, PHP_EOL; Output: 20 20 <--- Expected 21 20 21 20 21 Any idea why I got 20 instead of 21 ? Even then the code below works: $i = null ; echo ++$i ; // output 1 I know Group is an object that implements _