Programming
DE
Figuring Out Foreach
['Derick Rethans']
Derick Rethans
London, UKFor a while I have been aware of some odd behaviour when you use branch coverage with PHP's foreach language construct.
It seems that the emptiness of a normal array is checked by the FE_FETCH_R opcode.
Now the question is how to trigger the other path, so that 100% path (and branch) coverage can be reached.
I think I will now rather hide the jump away from the FE_RESET_R (and FE_RESET_RW ) opcode.
But at last I now have an explanation as to where this phantom path came from.
['iterator'
'fe_fetch_r'
'opcodes'
'return'
'paths'
'fe_reset_r'
'foreach'
'opcode'
'figuring'
'derick'
'path'
'language'
'ext_stmt'
'rethans']