如何获取PHP的操作码?

Mas*_*ask 72 php opcode

  <?php
      $show_value   = 123;
      echo 'sing_quote'.$show_value;
      echo "double_quote{$show_value}";

  ?>
Run Code Online (Sandbox Code Playgroud)

它的操作码是:

1: <?php
2: $show_value   = 123;
        0  ASSIGN              !0, 123
3: echo 'sing_quote'.$show_value;
        1  CONCAT              'sing_quote', !0 =>RES[~1]     
        2  ECHO                ~1
4: echo "double_quote{$show_value}";
        3  ADD_STRING          'double_quote' =>RES[~2]     
        4  ADD_VAR             ~2, !0 =>RES[~2]     
        5  ECHO                ~2
        6  RETURN              1
Run Code Online (Sandbox Code Playgroud)

Pau*_*xon 40

查看Vulcan Logic Disassembler PECL扩展 - 有关详细信息,请参阅作者的主页.

Vulcan Logic Disassembler挂钩到Zend Engine并转储脚本的所有操作码(执行单元).它被写成编码器的开头,但我从来没有时间.它可以用来查看Zend Engine中发生了什么.

安装后,您可以像这样使用它:

php -d vld.active=1 -d vld.execute=0 -f yourscript.php
Run Code Online (Sandbox Code Playgroud)

另请参阅这篇关于操作码提取的有趣博客文章,以及列出可用操作码PHP手册页.


Kor*_*nel 12

Parsekitparsekit_compile_string().

sudo pecl install parsekit
Run Code Online (Sandbox Code Playgroud)
var_dump(parsekit_compile_string(<<<PHP
 \$show_value   = 123;
 echo 'sing_quote'.\$show_value;
 echo "double_quote{\$show_value}";
PHP
));

输出非常详细,因此您需要处理它以获得类似汇编程序的格式.

  ["opcodes"]=>
  array(10) {
    [0]=>
    array(9) {
      ["address"]=>
      int(44682716)
      ["opcode"]=>
      int(101)
      ["opcode_name"]=>
      string(13) "ZEND_EXT_STMT"
      ["flags"]=>
      int(4294967295)
      ["result"]=>
      array(8) {
        ["type"]=>
        int(8)
        ["type_name"]=>
        string(9) "IS_UNUSED"
        ["var"]=>
        int(0)
        ["opline_num"]=>
        string(1) "0"
        ["op_array"]=>
        string(1) "0"
        ["jmp_addr"]=>
        string(1) "0"
        ["jmp_offset"]=>
        string(8) "35419039"
        ["EA.type"]=>
        int(0)
      }
      ["op1"]=>
      array(8) {
        ["type"]=>
        int(8)
        ["type_name"]=>
        string(9) "IS_UNUSED"
        ["var"]=>
        int(0)
        ["opline_num"]=>
        string(1) "0"
        ["op_array"]=>
        string(1) "0"
        ["jmp_addr"]=>
        string(1) "0"
        ["jmp_offset"]=>
        string(8) "35419039"
        ["EA.type"]=>
        int(0)
      }