Giter Site home page Giter Site logo

Comments (6)

nikic avatar nikic commented on July 19, 2024

As the syntax tree is discarded after compilation, reflection would effectively have to do the same as you describe: Parse the entire file and locate the desired node. (We'd also still have the problem of not being able to distinguish between two closures on the same line.)

Probably still useful. I won't be able to add this to reflection from here, but I can add functions to get the AST of specific classes and functions.

from php-ast.

TimeToogo avatar TimeToogo commented on July 19, 2024

That would be nice for built in functionality.
Perhaps PHP could eventually expose methods for absolute offsets of the code:

ReflectionFunctionAbstract::getStartOffset();
ReflectionFunctionAbstract::getEndOffset();

And remove all ambiguity and needless hoops that are currently being jumped through.

Sadly this takes some of the excitement away from this project for me, due to this becoming essentially a faster version of your php-parser project :/

from php-ast.

andyjansson avatar andyjansson commented on July 19, 2024

@nikic Any reason why the AST is discarded after compilation? Couldn't it be saved alongside the opcode cache?

from php-ast.

nikic avatar nikic commented on July 19, 2024

@andyjansson Syntax trees are large structures. Keeping them in memory for all functions would skyrocket our memory usage.

from php-ast.

nikic avatar nikic commented on July 19, 2024

Here's the ticket for more accurate position information: https://bugs.php.net/bug.php?id=70024 Even if we don't add it to the AST, we can at least add the info to reflection.

from php-ast.

nikic avatar nikic commented on July 19, 2024

Closing this, as it's out of scope for this extension and would require upstream changes in any case.

from php-ast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.