Comments (21)
Ping, @nikic ) Can we bump this thread to move this beautiful gem into the PHP7.1?
from php-ast.
@lisachenko It's still a bit early for PHP 7.1 (we haven't even branched yet), I'd wait until PHP 7 is out :)
from php-ast.
@nikic oh, it's ok ) Just want to see, that this topic is still interesting for you and php-AST can be moved to the PHP core in future versions.
from php-ast.
I, too, would love to see this bundled with and enabled by default for PHP 7.1.
from php-ast.
👍
from php-ast.
👍
from php-ast.
For anyone who wants this in the PHP core, here is a link to the draft version of RFC: https://wiki.php.net/rfc/parser-extension-api
from php-ast.
👍
from php-ast.
@lisachenko When Opcode caching is enabled, how will the hook API work? The same PHP file could be parsed into different Opcodes based on the bound transform functions.
from php-ast.
@JoyceBabu parsing, as well as possible hooks will be called only once with enabled opcode caching. There won't be any calls to the hooks, because source code AST will be transformed into an opcodes and cached by the engine.
from php-ast.
That is going to cause a lot of confusion to several users. Because any time varying or indeterministic code in the callback will retain the value of the first invocation.
But since this will be used mainly by advanced PHP users, proper documentation will reduce the confusion.
PS: This will be very useful when writing Templating Engines.
from php-ast.
PHP with enabled opcode caching working in the same way for production mode. All files are served directly from the memory, no file checks at all, if you want to upload a new version of file (for example, symfony container with new host names, passwords, etc) then you should call opcache_invalidate() function to keep opcodes in sync with original source code.
Hook is just additional logic to transform the AST source, nothing more. What is more important: how to register that hooks, because there will be time, when several core files are loaded (without enabled hook), then hook will be registered and only after that all next files will be analysed/transformed.
I can see two ways:
- put a class names into the php.ini, so they will be loaded by PHP immediately at the beginning of request
- leave as-is, like with
register_shutdown_function
,register_exception_handler
, etc - it's ok that some files won't be processed during the initialization of framework/application source code.
from php-ast.
+1
from php-ast.
+1
from php-ast.
👍
from php-ast.
@nikic @lisachenko any ideas on whether we can push this RFC along a bit? Would love to get AST available in core.
I have a question: if integrated into core, can I still parse the same code multiple times without actually loading the functions/classes within, or would it actually load e.g. the class entry?
from php-ast.
It doesn't actually load the class entry, it just parses it.
from php-ast.
It doesn't actually load the class entry, it just parses it.
Yep I understand that's the current operation, I was asking if integrated into core :) thanks!
from php-ast.
I'd expect that this would be integrated in core by simply bundling it, i.e. with the behavior entirely unchanged.
from php-ast.
Thanks for confirming! Any ideas if/when it might make into core?
from php-ast.
I'd definitely like to see this in core, since it would make it easier and more common to build/adopt simple and complex tools based on it, like the tools already built on tokenizer.
EDIT: But it would make writing tooling using the latest AST version(s) much, much harder if new ast versions couldn't be backported, so I doubt this would work
One possible issue with putting this in core is supporting new AST version numbers for ast\parse_code
and ast\parse_file
when new syntax requires breaking changes to the AST representation.
For example, in php 7.4, the new node kind AST_PROP_GROUP was added. So in AST version 70, all properties became part of an AST_PROP_GROUP when they would have been an AST_PROP_LIST in AST version 50.
If php-ast was part of the PHP core in php 7.3, it wouldn't be possible to php-ast to change in 7.3.x to support that due to needing a stable API. If a tool such as https://github.com/phan/phan was updated to support php 7.4 syntax, it would need to use AST version 70, but that would mean it couldn't run in php 7.3 (without making the AST imitate the newest AST version in a post-processing step)
AST_PROP_GROUP
was added to support PHP 7.4's typed properties.
The property visibility modifiers are now part ofAST_PROP_GROUP
instead ofAST_PROP_DECL
.
Note that property group type information is only available with AST versions 70+.
Constants such as TYPE_FALSE, TYPE_STATIC, etc. would also need to be polyfilled in php 7.3 for code that supported analyzing 7.4. (Currently, code/composer.json can just require a minimum php-ast version). This is doable and implemented in Phan, but a drawback.
EDIT(2020-07-15): And in php 8.0, the attributes syntax required at least one incompatible change for AST version 80
- AST_CLASS_CONST_GROUP was added where AST_CLASS_CONST_DECL was used
from php-ast.
Related Issues (20)
- 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 8
- Fails to Compile with PHP 8 includes (changed prototype for "zend_prepare_string_for_scanning()") HOT 2
- PHP 8.3 compatibility HOT 2
- Incorrect values for magic constants HOT 5
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.