The ending block of the "declare" statement (i.e. the "}") causes the tick to fire as well.
Note that it's not every itteration of the code, just every Nth line. So for tick=2, once you get to the 4th item in the array, the "}" will cause it to throw another tick. Plus the ending "}" causes the tick again as well.
Change your code to this:
function a(){
echo 'a';
}
$array = range(1,4);
declare(ticks=4){
echo '[begin]';
sleep(1);
foreach ($array as $i)
echo '['.$i.']';
echo '[end]';
}
unregister_tick_function("a");
And this output comes out:
[begin][1][2]a[3][4][end]a
Weedpacket or NogDog would probably be able to give you a better reason....