PHP, foreach and opline compilation

I am trying to understand how the foreach interpreter is interpreted by PHP. This made me use gdbwhile executing a dummy foreach script.

I end up in zend_compile.c in a function zend_compile_foreach(). I see a macro call ZEND_FE_FETCH_R, which moves the internal pointer of the array / object that we are executing.

There are a few things that I do not understand:

  • How value really returns to context zend_compile_foreach
  • Are we nested calls to zend_compile_stmt(and therefore zend_compile_foreach) to do an iteration? So the code compiles N times? N - the number of elements in the array / object
  • What is a point? I see that everywhere I look, and I do not know about it.
+4
source share

Source: https://habr.com/ru/post/1628506/


All Articles