Skip to content

Instantly share code, notes, and snippets.

@co3k
Created November 12, 2011 16:45
Show Gist options
  • Save co3k/1360791 to your computer and use it in GitHub Desktop.
Save co3k/1360791 to your computer and use it in GitHub Desktop.
<?php
// You need to clone https://github.com/nikic/PHP-Parser
require_once __DIR__.'/PHP-Parser/lib/PHPParser/Autoloader.php';
PHPParser_Autoloader::register();
class Teriyaki
{
public function __construct(Teriyaki $teriyaki, $ebichiri)
{
if ($teriyaki instanceof Teriyaki) {
var_dump('^^');
}
}
}
$parser = new PHPParser_Parser;
$stmts = $parser->parse(new PHPParser_Lexer(file_get_contents(__FILE__)));
$dumper = new PHPParser_NodeDumper;
var_dump($dumper->dump($stmts));
@co3k
Copy link
Author

co3k commented Nov 12, 2011

string(5371) "array(
    0: Expr_Include(
        expr: Expr_Concat(
            left: Scalar_DirConst(
            )
            right: Scalar_String(
                value: /PHP-Parser/lib/PHPParser/Autoloader.php
            )
        )
        type: 4
    )
    1: Expr_StaticCall(
        class: Name(
            parts: array(
                0: PHPParser_Autoloader
            )
        )
        name: register
        args: array(
        )
    )
    2: Stmt_Class(
        type: 0
        extends: null
        implements: array(
        )
        stmts: array(
            0: Stmt_ClassMethod(
                type: 1
                byRef: false
                params: array(
                    0: Param(
                        name: teriyaki
                        default: null
                        type: Name(
                            parts: array(
                                0: Teriyaki
                            )
                        )
                        byRef: false
                    )
                    1: Param(
                        name: ebichiri
                        default: null
                        type: null
                        byRef: false
                    )
                )
                stmts: array(
                    0: Stmt_If(
                        stmts: array(
                            0: Expr_FuncCall(
                                name: Name(
                                    parts: array(
                                        0: var_dump
                                    )
                                )
                                args: array(
                                    0: Arg(
                                        value: Scalar_String(
                                            value: ^^
                                        )
                                        byRef: false
                                    )
                                )
                            )
                        )
                        elseifs: array(
                        )
                        else: null
                        cond: Expr_Instanceof(
                            expr: Expr_Variable(
                                name: teriyaki
                            )
                            class: Name(
                                parts: array(
                                    0: Teriyaki
                                )
                            )
                        )
                    )
                )
                name: __construct
            )
        )
        name: Teriyaki
    )
    3: Expr_Assign(
        var: Expr_Variable(
            name: parser
        )
        expr: Expr_New(
            class: Name(
                parts: array(
                    0: PHPParser_Parser
                )
            )
            args: array(
            )
        )
    )
    4: Expr_Assign(
        var: Expr_Variable(
            name: stmts
        )
        expr: Expr_MethodCall(
            var: Expr_Variable(
                name: parser
            )
            name: parse
            args: array(
                0: Arg(
                    value: Expr_New(
                        class: Name(
                            parts: array(
                                0: PHPParser_Lexer
                            )
                        )
                        args: array(
                            0: Arg(
                                value: Expr_FuncCall(
                                    name: Name(
                                        parts: array(
                                            0: file_get_contents
                                        )
                                    )
                                    args: array(
                                        0: Arg(
                                            value: Scalar_FileConst(
                                            )
                                            byRef: false
                                        )
                                    )
                                )
                                byRef: false
                            )
                        )
                    )
                    byRef: false
                )
            )
        )
    )
    5: Expr_Assign(
        var: Expr_Variable(
            name: dumper
        )
        expr: Expr_New(
            class: Name(
                parts: array(
                    0: PHPParser_NodeDumper
                )
            )
            args: array(
            )
        )
    )
    6: Expr_FuncCall(
        name: Name(
            parts: array(
                0: var_dump
            )
        )
        args: array(
            0: Arg(
                value: Expr_MethodCall(
                    var: Expr_Variable(
                        name: dumper
                    )
                    name: dump
                    args: array(
                        0: Arg(
                            value: Expr_Variable(
                                name: stmts
                            )
                            byRef: false
                        )
                    )
                )
                byRef: false
            )
        )
    )
)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment