I'm trying to figure out how a foreach statement is interpreted by PHP. That led me to use gdb
while executing a dummy foreach script.
I end up in zend_compile.c, in the zend_compile_foreach()
function. I see the call to the macro ZEND_FE_FETCH_R that moves the internal pointer of the array/object we loop on.
There are a few things I don't understand :
- How the value is actually returned to the
zend_compile_foreach
context - Are we nesting calls to
zend_compile_stmt
(and thereforezend_compile_foreach
) to make the iteration happen ? So is the code compiled N times ? N being the number of elements in the array/object - What is an opline ?? I see that everywhere I look and I don't know about this