o0h/astop 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

o0h/astop

最新稳定版本:0.0.2

Composer 安装命令:

pie install o0h/astop

包简介

A PHP extension that intercepts the compilation pipeline and prints the AST and opcodes

README 文档

README

A PHP extension that intercepts the compilation pipeline and prints the AST and opcodes for every file or string compiled during a request.

Note: This project is a personal learning exercise to explore PHP internals — the compiler pipeline, AST structure, and opcode generation. It is not intended for production use.

What it does

When loaded, astop hooks into three PHP internals:

Hook What it captures
zend_ast_process AST produced after parsing
zend_compile_file Opcodes for each compiled file
zend_compile_string Opcodes for eval() / assert() strings

An optional no-exec mode (ASTOP_MODE=no_exec) also replaces zend_execute_ex with a no-op, so you can inspect compilation output without actually running the code.

Docker

The easiest way to try it out — no PHP dev headers needed locally.

docker build -t astop .

Run an inline snippet:

docker run --rm astop -r 'echo "hello";'

Run a local file:

docker run --rm -v "$(pwd):/work" astop /work/your_script.php

no_exec mode (dump only, skip execution):

docker run --rm -e ASTOP_MODE=no_exec -v "$(pwd):/work" astop /work/your_script.php

Install via PIE

PIE is the official PHP extension installer.

pie install o0h/astop

Build from source

phpize
./configure
make

The extension will be built at modules/astop.so.

Usage

Basic — dump AST and opcodes, then run the script

php -d extension=modules/astop.so your_script.php

no_exec — dump only, skip execution

ASTOP_MODE=no_exec php -d extension=modules/astop.so your_script.php

Example

<?php
echo "hello";
=== AST ===
ZEND_AST_STMT_LIST lineno=1
  stmt[0]: ZEND_AST_STMT_LIST lineno=2
    stmt[0]: ZEND_AST_ECHO lineno=2
      expr: ZEND_AST_ZVAL("hello") lineno=2

=== OPCODES {main} ===
  line  num  opcode                     op1           op2           result
     2    0  ZEND_ECHO                  "hello"       -             -
     3    1  ZEND_RETURN                1             -             -

hello

With ASTOP_MODE=no_exec, the AST and opcode sections appear as above but hello is not printed.

Running tests

make test

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: C

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固