rfc:abstract_syntax_tree
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:abstract_syntax_tree [2014/08/18 10:10] – nikic | rfc:abstract_syntax_tree [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
* Date: 2014-07-28 | * Date: 2014-07-28 | ||
* Author: Nikita Popov < | * Author: Nikita Popov < | ||
- | * Status: | + | * Status: |
- | * Targeting: PHP.next | + | * Discussion: http:// |
===== Introduction ===== | ===== Introduction ===== | ||
Line 95: | Line 95: | ||
==== Changes to list() ==== | ==== Changes to list() ==== | ||
+ | |||
+ | > **Note**: The behavior of '' | ||
'' | '' | ||
Line 147: | Line 149: | ||
==== Auto-vivification order for by-reference assignments ==== | ==== Auto-vivification order for by-reference assignments ==== | ||
+ | |||
+ | > **Note**: The auto-vivification order for reference assignments has been restored to the old behavior in PHP 7.1. The reason for this is that we found hard to avoid memory safety issues with the new order. | ||
While by-reference assignments are (CVs notwithstanding) evaluated left-to-right, | While by-reference assignments are (CVs notwithstanding) evaluated left-to-right, | ||
Line 178: | Line 182: | ||
Doing calls like '' | Doing calls like '' | ||
- | |||
- | ===== Additional possibilities (not implemented) ===== | ||
- | |||
- | The generated AST can be exposed to userland via an extension, for use by static analysers. This should be relatively easy to implement and we might even want to provide this as a bundled extension (like ext/ | ||
- | |||
- | More interestingly, | ||
- | |||
- | As an example, this is roughly how an implementation of the [[rfc: | ||
- | |||
- | <code c> | ||
- | /* Works by rewriting ifsetor($foo, | ||
- | void ext_ifsetor_hook(zend_ast **ast_ptr TSRMLS_DC) { | ||
- | zend_ast *ast = *ast_ptr; | ||
- | | ||
- | if (ast-> | ||
- | zend_string *name = zval_get_string(zend_ast_get_zval(ast-> | ||
- | zend_ast_list *args = zend_ast_get_list(ast-> | ||
- | | ||
- | if (zend_str_equals_literal_ci(name, | ||
- | && args-> | ||
- | ) { | ||
- | if (!zend_is_variable(args-> | ||
- | zend_error_noreturn(E_COMPILE_ERROR, | ||
- | "must be a variable" | ||
- | } | ||
- | | ||
- | /* Note: One would need a function for adding refs to args-> | ||
- | * as it is used two times - as written here it won't work correctly. */ | ||
- | *ast_ptr = zend_ast_create(ZEND_AST_CONDITIONAL, | ||
- | zend_ast_create(ZEND_AST_ISSET, | ||
- | args-> | ||
- | args-> | ||
- | ); | ||
- | } | ||
- | | ||
- | STR_RELEASE(name); | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | I don't know how useful this is and how many things can be implemented in this way, but I think it's worth considering. | ||
- | |||
- | An additional possibility is to drop the keywords for '' | ||
- | |||
- | ===== Patch ===== | ||
- | |||
- | The AST implementation can be found at https:// | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | The branch is based on phpng and already includes the Uniform Variable Syntax RFC, as it was a necessary prerequisite for the implementation. | ||
- | |||
- | The implementation has everything ported, but probably still has some bugs and needs some cleanup :) | ||
===== Implementation ===== | ===== Implementation ===== | ||
Line 541: | Line 489: | ||
The '' | The '' | ||
+ | |||
+ | ===== Additional possibilities (not implemented) ===== | ||
+ | |||
+ | The generated AST can be exposed to userland via an extension, for use by static analysers. This should be relatively easy to implement and we might even want to provide this as a bundled extension (like ext/ | ||
+ | |||
+ | More interestingly, | ||
+ | |||
+ | As an example, this is roughly how an implementation of the [[rfc: | ||
+ | |||
+ | <code c> | ||
+ | /* Works by rewriting ifsetor($foo, | ||
+ | void ext_ifsetor_hook(zend_ast **ast_ptr TSRMLS_DC) { | ||
+ | zend_ast *ast = *ast_ptr; | ||
+ | | ||
+ | if (ast-> | ||
+ | zend_string *name = zval_get_string(zend_ast_get_zval(ast-> | ||
+ | zend_ast_list *args = zend_ast_get_list(ast-> | ||
+ | | ||
+ | if (zend_str_equals_literal_ci(name, | ||
+ | && args-> | ||
+ | ) { | ||
+ | if (!zend_is_variable(args-> | ||
+ | zend_error_noreturn(E_COMPILE_ERROR, | ||
+ | "must be a variable" | ||
+ | } | ||
+ | | ||
+ | /* Note: One would need a function for adding refs to args-> | ||
+ | * as it is used two times - as written here it won't work correctly. */ | ||
+ | *ast_ptr = zend_ast_create(ZEND_AST_CONDITIONAL, | ||
+ | zend_ast_create(ZEND_AST_ISSET, | ||
+ | args-> | ||
+ | args-> | ||
+ | ); | ||
+ | } | ||
+ | | ||
+ | STR_RELEASE(name); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | I don't know how useful this is and how many things can be implemented in this way, but I think it's worth considering. | ||
+ | |||
+ | An additional possibility is to drop the keywords for '' | ||
+ | |||
+ | ===== Patch ===== | ||
+ | |||
+ | The AST implementation can be found at https:// | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | //The branch already includes the Uniform Variable Syntax RFC//, as it was a necessary prerequisite for the implementation. | ||
+ | |||
+ | The implementation has everything ported, but probably still has some bugs and needs some cleanup :) | ||
+ | |||
+ | ===== Vote ===== | ||
+ | The vote started on 2014-08-18 and ended on 2014-08-25. The necessary 2/3 majority was reached, as such the RFC is accepted. | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ |
rfc/abstract_syntax_tree.1408356630.txt.gz · Last modified: 2017/09/22 13:28 (external edit)