mrsuh/php-ast

Maintainers

Details

github.com/mrsuh/php-ast

Source

Issues

Installs: 11

Dependents: 0

Suggesters: 0

Security: 0

Stars: 15

Watchers: 1

Forks: 0

Open Issues: 0

Language:C

0.2.0 2022-12-09 08:25 UTC

This package is auto-updated.

Last update: 2024-04-09 11:19:18 UTC


README

Tests

Requirements

  • PHP >= 8.0 (with FFI)
  • Linux(x86_64) / Darwin(x86_64)

Usage

composer require mrsuh/php-ast
<?php

require __DIR__. '/vendor/autoload.php';

use Mrsuh\PhpAst\Parser;
use Mrsuh\PhpAst\Printer;

$code = <<<'CODE'
<?php

namespace App;

class Test
{
    public function test($foo)
    {
        var_dump($foo);
    }
}
CODE;

$node = Parser::parse($code);
Printer::print($node);
[001] ZEND_AST_STMT_LIST
[003]   ZEND_AST_NAMESPACE
[003]     ZEND_AST_ZVAL "App"
[005]   ZEND_AST_CLASS "Test"
[006]     ZEND_AST_STMT_LIST
[007]       ZEND_AST_METHOD "test"
[007]         ZEND_AST_PARAM_LIST
[007]           ZEND_AST_PARAM
[007]             ZEND_AST_ZVAL "foo"
[008]         ZEND_AST_STMT_LIST
[009]           ZEND_AST_CALL
[009]             ZEND_AST_ZVAL "var_dump"
[009]             ZEND_AST_ARG_LIST
[009]               ZEND_AST_VAR
[009]                 ZEND_AST_ZVAL "foo"

For contributors

How to compile

git clone --recurse-submodules git@github.com:mrsuh/php-ast.git && cd php-ast
make php-src
make

Debug

make debug
gdb php
run bin/test.php

Docker

docker build -t php-ast .
docker run --rm -v $PWD:/code -it php-ast bash
make
php bin/test.php