Comments (6)
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.
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.
@nikic Any reason why the AST is discarded after compilation? Couldn't it be saved alongside the opcode cache?
from php-ast.
@andyjansson Syntax trees are large structures. Keeping them in memory for all functions would skyrocket our memory usage.
from php-ast.
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.
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)
- Supporting TYPE_MIXED from php 8.0 mixed type HOT 4
- Support php 8.0 attributes
- Idea: Adding new parameter flag PARAM_MODIFIER_PUBLIC for AST_PARAM HOT 1
- Changing values of constants HOT 4
- Support ZEND_AST_ATTRIBUTE_GROUP for #[Attr1, Attr2] HOT 1
- Make version 80 the current version
- Dropping support for php 7.1 and older? HOT 2
- Test failing with 8.0.0beta4 HOT 2
- Add ast_dump option: AST_DUMP_EXCLUDE_DOC HOT 2
- Utilize in C# (e.g. exposing php-ast as a standalone library that can be used from other programming languages) HOT 1
- Travis -> GH Actions HOT 4
- make command error HOT 2
- Idea: Make ast\Node->endLineno a declared property? HOT 5
- Windows: Pecl DLL for PHP 8.1 HOT 8
- Question about class `implements` and `extends` HOT 1
- Why some built-in functions have special AST type ? HOT 1
- Expose php 8.2 `ENCAPS_VAR_DOLLAR_CURLY*` flags in ast\flags
- php 8.2 changed the ast representation of short arrow functions HOT 1
- [question] How to list all classes that used in a file? HOT 2
- php-ast 1.1.0 DLL for Windows HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-ast.