recently I did a test on return reference function follow the official example here , but confused with the result when return '++$a' instead, it seems they should be same from the answer What's the difference between ++$i and $i++ in PHP? It seems related to the version of PHP.
php version
PHP 5.6.28 (cli) (built: Dec 6 2016 12:38:54)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
code
function &fun(){
static $var = 1;
return ++$var;
}
function &bar() {
static $var = 1;
++$var;
return $var;
}
$var2 =& fun();
$var3 =& bar();
fun();
bar();
echo 'var2:', $var2; // 2 why is it 2 instead of 3?
echo 'var3:', $var3; // 3