What is EXT_NOP and EXT_STMT, PHP Opcode

541 Views Asked by At

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
1

There are 1 best solutions below

1
Derick On BEST ANSWER

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.