Giter Site home page Giter Site logo

Comments (21)

lisachenko avatar lisachenko commented on August 19, 2024

Ping, @nikic ) Can we bump this thread to move this beautiful gem into the PHP7.1?

from php-ast.

nikic avatar nikic commented on August 19, 2024

@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.

lisachenko avatar lisachenko commented on August 19, 2024

@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.

sebastianbergmann avatar sebastianbergmann commented on August 19, 2024

I, too, would love to see this bundled with and enabled by default for PHP 7.1.

from php-ast.

GrahamCampbell avatar GrahamCampbell commented on August 19, 2024

👍

from php-ast.

JoyceBabu avatar JoyceBabu commented on August 19, 2024

👍

from php-ast.

lisachenko avatar lisachenko commented on August 19, 2024

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.

funivan avatar funivan commented on August 19, 2024

👍

from php-ast.

JoyceBabu avatar JoyceBabu commented on August 19, 2024

@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.

lisachenko avatar lisachenko commented on August 19, 2024

@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.

JoyceBabu avatar JoyceBabu commented on August 19, 2024

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.

lisachenko avatar lisachenko commented on August 19, 2024

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.

msjyoo avatar msjyoo commented on August 19, 2024

+1

from php-ast.

jansor avatar jansor commented on August 19, 2024

+1

from php-ast.

jeremeamia avatar jeremeamia commented on August 19, 2024

👍

from php-ast.

asgrim avatar asgrim commented on August 19, 2024

@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.

TysonAndre avatar TysonAndre commented on August 19, 2024

It doesn't actually load the class entry, it just parses it.

from php-ast.

asgrim avatar asgrim commented on August 19, 2024

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.

nikic avatar nikic commented on August 19, 2024

I'd expect that this would be integrated in core by simply bundling it, i.e. with the behavior entirely unchanged.

from php-ast.

asgrim avatar asgrim commented on August 19, 2024

Thanks for confirming! Any ideas if/when it might make into core?

from php-ast.

TysonAndre avatar TysonAndre commented on August 19, 2024

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 of AST_PROP_GROUP instead of AST_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)

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.