4

I'm trying to understand more deep and php internals by just executing native php functions against to my implementations.

But in every opcode dump I see these two following opcodes :

EXT_NOP : http://php.net/manual/tr/internals2.opcodes.ext-nop.php

EXT_STMT : http://php.net/manual/tr/internals2.opcodes.ext-stmt.php

as you see in docs there is no detailed explanation.

Even in following example which given in the doc my dumps are different than the doc's spesification. I really want to know why are these two stands in every dump ? What is their functionality ?

<?php
/*
 * no operation
 * opcode number: 0
 */
function A(){}; 
?>

Env Spesification :

LXC
Linux web 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u5 (2015-10-09) x86_64 GNU/Linux  
PHP 5.6.15-1~dotdeb+7.1 (cli) (built: Nov  3 2015 16:29:58) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

OpCode Dump :

➜  php -d vld.active=1 -d vld.execute=0 -f nop.php
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /root/web/www/optest/nop.php
function name:  (null)
number of ops:  5
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   EXT_STMT                                                 
         1        NOP                                                      
         2        NOP                                                      
   4     3        EXT_STMT                                                 
         4      > RETURN                                                   1

branch: #  0; line:     2-    4; sop:     0; eop:     4; out1:  -2
path #1: 0, 
Function a:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /root/web/www/optest/nop.php
function name:  A
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   EXT_NOP                                                  
         1        EXT_STMT                                                 
         2      > RETURN                                                   null

branch: #  0; line:     2-    2; sop:     0; eop:     2; out1:  -2
path #1: 0, 
End of function a
FZE
  • 1,587
  • 12
  • 35
  • To me the EXT_STMT opcode seems like it's there everytime you start a new "extension". Lets say you declare a variable, the opcode of declaring that variable will start with EXT_STMT and if you use that variable for let's say in a loop, that representation of a loop and checks etc will start with EXT_STMT. Seems as every "process of thinking" starts by making a new extension with the ext_stmt. Try it out with a for-loop or foreach statement, a simple 1. – izk Mar 16 '16 at 09:58
  • https://gist.github.com/feyyazesat/87751632614f7bd86131 I played with a little bit as you said ext_stmt is for the new extention, but I really didn't understand what the extention means in this context. In training, what I see open and closing php tags, definition of a variable, and a function represents an EXT_STMT for each. But it is interesting there is no sign for `class { }` definition in opcode. – FZE Mar 16 '16 at 10:15

1 Answers1

6

EXT_NOP is used in the cases where previously there was something to do (ie a function declaration), but the engine has internally already taken care of this, and replaced the original opcode with EXT_NOP. NOP stands for "no operation". NOP is slightly different from EXT_NOP, as it's generated at different times, but it does the same thing: Nothing.

EXT_STMT is created in between statements, and allows debuggers (such as Xdebug) to stop in safe locations. Xdebug uses a "statement handler" (https://github.com/derickr/xdebug/blob/master/xdebug.c#L2534) to hook into the Zend Engine. The Zend Engine calls this handler for each EXT_STMT opcode it encounters.

Derick
  • 35,169
  • 5
  • 76
  • 99
  • 1
    Thanks Derick for the clarification, it really clarified me. EXT_STMT is just for debuggers, there is no other functionality in the program itself, and differences between EXT_NOP and NOP just for the internal categorization purpose of the no operations ? That I understand correctly ? – FZE Mar 16 '16 at 10:21