0

Using PHP-Parser, when I am traversing the nodes in a program, how do I find the type of an object? For example, in the program below, when I encounter the node $a->some_method(); how do I find that $a's type is 'TestClass' ?

$a = new TestClass();

$a->some_method();

Now, I know that I can keep track internally that the object $a is of the type TestClass and that works fine for programs in a single file, but I'm not sure how to keep track of the type of an object in programs that span multiple files and I'm particularly confused about how to maintain the type of a variable when it is returned from a function or method. Am I going about it all wrong? Is there a simpler way using PHP-Parser to find out the type of an object?

1
  • A parser really just turns the source code into an AST. It does not evaluate types at all, that'd be the next step in the chain and the job of the compiler. You'll have to do this yourself. Commented Jul 13, 2015 at 8:57

1 Answer 1

0

The short answer is: you can't.

It's not possible to do it without actually executing the code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.