<?php
class Test
{
public function foo()
{
echo "I am only called once.\n";
return array('a', 'b', 'c', 'd', 'e');
}
public function count($arr)
{
echo "I am only called once.\n";
return count($arr);
}
}
$test = new Test();
foreach ($test->foo() as $value) {
echo $value . "\n";
}
$arr = array(1,2,3,4,5);
for($i=0; $i < $test->count($arr); ++$i) {
echo $arr[$i] . "\n";
}
I am only called once.
a
b
c
d
e
I am only called once.
1
I am only called once.
2
I am only called once.
3
I am only called once.
4
I am only called once.
5
I am only called once.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/TXIcK on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/TXIcK on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/TXIcK on line 5
Process exited with code 255.