Skip to content

Commit 91f5946

Browse files
authored
php-ast 1.1.0dev: Deprecate AST versions 50 and 60, drop support for php < 7.2 (#185)
* Deprecate AST versions 50 and 60 AST version 70 has been supported since php-ast 1.0.1 (2019-02-11). Related to #114 * Drop support for php <= 7.1 Update documentation to mention this. * Update test expectation for AST version 60 deprecation
1 parent f2f7cad commit 91f5946

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+385
-227
lines changed

.appveyor.yml

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -69,46 +69,6 @@ environment:
6969
VC: vs16
7070
PHP_VER: 8.0.13
7171
TS: 0
72-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
73-
ARCH: x64
74-
VC: vc14
75-
PHP_VER: 7.0.33
76-
TS: 0
77-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
78-
ARCH: x64
79-
VC: vc14
80-
PHP_VER: 7.0.33
81-
TS: 1
82-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
83-
ARCH: x86
84-
VC: vc14
85-
PHP_VER: 7.0.33
86-
TS: 0
87-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
88-
ARCH: x86
89-
VC: vc14
90-
PHP_VER: 7.0.33
91-
TS: 1
92-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
93-
ARCH: x64
94-
VC: vc14
95-
PHP_VER: 7.1.33
96-
TS: 0
97-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
98-
ARCH: x64
99-
VC: vc14
100-
PHP_VER: 7.1.33
101-
TS: 1
102-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
103-
ARCH: x86
104-
VC: vc14
105-
PHP_VER: 7.1.33
106-
TS: 0
107-
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
108-
ARCH: x86
109-
VC: vc14
110-
PHP_VER: 7.1.33
111-
TS: 1
11272
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
11373
ARCH: x64
11474
VC: vc15

.github/workflows/main.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
include:
28-
# NOTE: If this is not quoted, the yaml parser will convert 7.0 to the number 7,
29-
# and the docker image `php:7` is the latest minor version of php 7.x (7.4).
30-
- PHP_VERSION: '7.0'
31-
- PHP_VERSION: '7.1'
28+
# NOTE: If this is not quoted, the yaml parser will convert 8.0 to the number 8,
29+
# and the docker image `php:8` is the latest minor version of php 8.x (8.1).
3230
- PHP_VERSION: '7.2'
3331
- PHP_VERSION: '7.3'
3432
- PHP_VERSION: '7.4'

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
php-ast
22
=======
33

4-
This extension exposes the abstract syntax tree generated by PHP 7.
4+
This extension exposes the abstract syntax tree generated by PHP 7 and 8.
55

6-
**This is the documentation for version 1.0.x. See also [documentation for version 0.1.x][v0_1_x].**
6+
**This is the documentation for version 1.x.y. See also [documentation for version 0.1.x][v0_1_x].**
77

88
Table of Contents
99
-----------------
@@ -529,18 +529,20 @@ Supported since 1.0.1 (2019-02-11).
529529
Note that property group type information is only available with AST versions 70+.
530530
* `AST_CLASS_NAME` is created instead of `AST_CLASS_CONST` for `SomeClass::class`.
531531

532-
### 60 (stable)
532+
### 60 (deprecated)
533533

534534
Supported since 0.1.7 (2018-10-06).
535+
Deprecated in php-ast 1.1.0.
535536

536537
* `AST_FUNC_DECL` and `AST_METHOD` no longer generate a `uses` child. Previously this child was
537538
always `null`.
538539
* `AST_CONST_ELEM` now always has a `docComment` child. Previously it was absent on PHP 7.0.
539540
On PHP 7.0 the value is always `null`.
540541

541-
### 50 (stable)
542+
### 50 (deprecated)
542543

543544
Supported since 0.1.5 (2017-07-19).
545+
Deprecated in php-ast 1.1.0.
544546

545547
This is the oldest AST version available in 1.0.0. See the
546548
[0.1.x AST version changelog][v0_1_x_versions] for information on changes prior to this version.
@@ -553,19 +555,19 @@ this extension. This section summarizes the main differences between php-ast and
553555
may decide which is preferable for your use-case.
554556

555557
The primary difference is that php-ast is a PHP extension (written in C) which exports the AST
556-
internally used by PHP 7. PHP-Parser on the other hand is library written in PHP. This has a number
558+
internally used by PHP 7 and 8. PHP-Parser on the other hand is library written in PHP. This has a number
557559
of consequences:
558560

559561
* php-ast is significantly faster than PHP-Parser, because the AST construction is implemented in
560562
C.
561563
* php-ast needs to be installed as an extension, on Linux either by compiling it manually or
562564
retrieving it from a package manager, on Windows by loading a DLL. PHP-Parser is installed as a
563565
Composer dependency.
564-
* php-ast only runs on PHP >= 7.0, as prior versions did not use an internal AST. PHP-Parser
566+
* php-ast only runs on PHP >= 7.0 (php-ast 1.0.16 was the last version supporting php <= 7.1), as prior versions did not use an internal AST. PHP-Parser
565567
supports PHP >= 5.5.
566568
* php-ast may only parse code that is syntactically valid on the version of PHP it runs on. This
567-
means that it's not possible to parse code using features of newer versions (e.g. PHP 7.1 code
568-
while running on PHP 7.0). Similarly, it is not possible to parse code that is no longer
569+
means that it's not possible to parse code using features of newer versions (e.g. PHP 7.4 code
570+
while running on PHP 7.2). Similarly, it is not possible to parse code that is no longer
569571
syntactically valid on the used version (e.g. some PHP 5 code may no longer be parsed -- however
570572
most code will work). PHP-Parser supports parsing both newer and older (up to PHP 5.2) versions.
571573
* php-ast can only parse code which is syntactically valid, while PHP-Parser can provide a partial

ast.c

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "zend_attributes.h"
2020
#endif
2121

22+
#if PHP_VERSION_ID < 70200
23+
#error "The php-ast 1.1 release dropped support for php 7.0-7.1. Use php-ast 1.0.16 instead."
24+
#endif
25+
2226
#ifndef ZEND_THIS
2327
#define ZEND_THIS getThis()
2428
#endif
@@ -27,12 +31,6 @@
2731
#define ZEND_ARG_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, default_value) \
2832
ZEND_ARG_INFO(pass_by_ref, name)
2933
#endif
30-
#if PHP_VERSION_ID < 70200
31-
#undef ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX
32-
#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
33-
static const zend_internal_arg_info name[] = { \
34-
{ (const char*)(zend_uintptr_t)(required_num_args), ( #class_name ), 0, return_reference, allow_null, 0 },
35-
#endif
3634

3735
#ifndef ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX
3836
#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
@@ -87,16 +85,6 @@
8785
#define AST_PLUS 261
8886
#define AST_MINUS 262
8987

90-
/* Define some compatibility constants */
91-
#if PHP_VERSION_ID < 70100
92-
# define IS_VOID 18
93-
# define IS_ITERABLE 19
94-
# define ZEND_TYPE_NULLABLE (1<<8)
95-
# define ZEND_ARRAY_SYNTAX_LIST 1
96-
# define ZEND_ARRAY_SYNTAX_LONG 2
97-
# define ZEND_ARRAY_SYNTAX_SHORT 3
98-
#endif
99-
10088
#if PHP_VERSION_ID < 70300
10189
# define ZEND_BIND_REF 1
10290
#endif
@@ -764,16 +752,6 @@ static void ast_fill_children_ht(HashTable *ht, zend_ast *ast, ast_state_info_t
764752
}
765753
}
766754
#endif
767-
#endif
768-
/* This AST_CATCH check should occur before ast_is_name() */
769-
#if PHP_VERSION_ID < 70100
770-
if (ast_kind == ZEND_AST_CATCH && i == 0) {
771-
/* Emulate PHP 7.1 format (name list) */
772-
zval tmp;
773-
ast_create_virtual_node(&tmp, AST_NAME, child->attr, child, state);
774-
ast_create_virtual_node_ex(
775-
&child_zv, ZEND_AST_NAME_LIST, 0, zend_ast_get_lineno(child), state, 1, &tmp);
776-
} else
777755
#endif
778756
if (ast_is_name(child, ast, i)) {
779757
ast_name_to_zval(child, ast, &child_zv, i, state);
@@ -803,21 +781,9 @@ static void ast_fill_children_ht(HashTable *ht, zend_ast *ast, ast_state_info_t
803781
/* Skip "uses" child since it is always empty */
804782
continue;
805783
#endif
806-
#if PHP_VERSION_ID >= 70100
807784
} else if (ast_kind == ZEND_AST_LIST && child != NULL) {
808785
/* Emulate simple variable list */
809786
ast_to_zval(&child_zv, child->child[0], state);
810-
#else
811-
} else if (ast_kind == ZEND_AST_ARRAY
812-
&& ast->attr == ZEND_ARRAY_SYNTAX_LIST && child != NULL) {
813-
/* Emulate ARRAY_ELEM list */
814-
zval ch0, ch1;
815-
ast_to_zval(&ch0, child, state);
816-
ZVAL_NULL(&ch1);
817-
ast_create_virtual_node_ex(
818-
&child_zv, ZEND_AST_ARRAY_ELEM, 0, zend_ast_get_lineno(child), state,
819-
2, &ch0, &ch1);
820-
#endif
821787
} else {
822788
ast_to_zval(&child_zv, child, state);
823789
}
@@ -840,15 +806,6 @@ static void ast_fill_children_ht(HashTable *ht, zend_ast *ast, ast_state_info_t
840806

841807
}
842808

843-
#if PHP_VERSION_ID < 70100
844-
/* Emulate docComment on constants, which is not available in PHP 7.0 */
845-
if (state->version >= 60 && ast_kind == ZEND_AST_CONST_ELEM) {
846-
zval tmp;
847-
ZVAL_NULL(&tmp);
848-
zend_hash_add_new(ht, AST_STR(str_docComment), &tmp);
849-
return;
850-
}
851-
#endif
852809
#if PHP_VERSION_ID < 80000
853810
if (state->version >= 80) {
854811
if (ast_kind == ZEND_AST_PARAM) {
@@ -1020,14 +977,6 @@ static void ast_to_zval(zval *zv, zend_ast *ast, ast_state_info_t *state) {
1020977
#endif
1021978
}
1022979

1023-
#if PHP_VERSION_ID < 70100
1024-
/* Normalize to PHP 7.1 format */
1025-
if (ast->kind == ZEND_AST_LIST) {
1026-
ast->kind = ZEND_AST_ARRAY;
1027-
ast->attr = ZEND_ARRAY_SYNTAX_LIST;
1028-
}
1029-
#endif
1030-
1031980
object_init_ex(zv, ast_node_ce);
1032981

1033982
zend_object *obj = Z_OBJ_P(zv);
@@ -1065,11 +1014,6 @@ static void ast_to_zval(zval *zv, zend_ast *ast, ast_state_info_t *state) {
10651014

10661015
zend_hash_add_new(children, AST_STR(str_docComment), &tmp_zv);
10671016
} else {
1068-
#if PHP_VERSION_ID < 70100
1069-
if (ast->kind == ZEND_AST_CLASS_CONST_DECL) {
1070-
ast->attr = ZEND_ACC_PUBLIC;
1071-
}
1072-
#endif
10731017
AST_NODE_SET_PROP_FLAGS(obj, ast->attr);
10741018
}
10751019

@@ -1110,8 +1054,7 @@ static const zend_long versions[] = {50, 60, 70, 80, 85, 90};
11101054
static const size_t versions_count = sizeof(versions)/sizeof(versions[0]);
11111055

11121056
static inline zend_bool ast_version_deprecated(zend_long version) {
1113-
/* Currently no deprecated versions */
1114-
return 0;
1057+
return version < 70;
11151058
}
11161059

11171060
static zend_string *ast_version_info() {
@@ -1512,15 +1455,9 @@ PHP_MINIT_FUNCTION(ast) {
15121455
ast_register_flag_constant("EXEC_REQUIRE", ZEND_REQUIRE);
15131456
ast_register_flag_constant("EXEC_REQUIRE_ONCE", ZEND_REQUIRE_ONCE);
15141457

1515-
#if PHP_VERSION_ID >= 70200
15161458
ast_register_flag_constant("USE_NORMAL", ZEND_SYMBOL_CLASS);
15171459
ast_register_flag_constant("USE_FUNCTION", ZEND_SYMBOL_FUNCTION);
15181460
ast_register_flag_constant("USE_CONST", ZEND_SYMBOL_CONST);
1519-
#else
1520-
ast_register_flag_constant("USE_NORMAL", T_CLASS);
1521-
ast_register_flag_constant("USE_FUNCTION", T_FUNCTION);
1522-
ast_register_flag_constant("USE_CONST", T_CONST);
1523-
#endif
15241461

15251462
ast_register_flag_constant("MAGIC_LINE", T_LINE);
15261463
ast_register_flag_constant("MAGIC_FILE", T_FILE);

package.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
</lead>
2121
<date>2022-02-12</date>
2222
<version>
23-
<release>1.0.17dev</release>
24-
<api>1.0.17dev</api>
23+
<release>1.1.0dev</release>
24+
<api>1.1.0dev</api>
2525
</version>
2626
<stability>
2727
<release>stable</release>
@@ -30,6 +30,8 @@
3030
<license uri="https://github.com/nikic/php-ast/blob/master/LICENSE">BSD-3-Clause</license>
3131
<notes>
3232
- Change documentation files to properly namespace attributes as `#[\AllowDynamicProperties]`. The reflection attributes are already correct.
33+
- Deprecated AST versions 50 and 60.
34+
- Drop support for php &lt;= 7.1
3335
</notes>
3436
<contents>
3537
<dir name="/">
@@ -133,7 +135,7 @@
133135
<dependencies>
134136
<required>
135137
<php>
136-
<min>7.0.0</min>
138+
<min>7.2.0</min>
137139
</php>
138140
<pearinstaller>
139141
<min>1.10.0</min>
@@ -157,6 +159,7 @@
157159
<notes>
158160
- Optimize instantiating properties of ast\Node and ast\Metadata.
159161
- Document that ast\Node implements `#[AllowDynamicProperties]` in php 8.2
162+
- Allow ast\Node to have dynamic properties without emitting a notice in PHP 8.2.
160163
</notes>
161164
</release>
162165
<release>

php_ast.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
extern zend_module_entry ast_module_entry;
88
#define phpext_ast_ptr &ast_module_entry
99

10-
#define PHP_AST_VERSION "1.0.17dev"
10+
#define PHP_AST_VERSION "1.1.0dev"
1111

1212
#ifdef PHP_WIN32
1313
# define PHP_AST_API __declspec(dllexport)
@@ -82,9 +82,7 @@ extern ast_str_globals str_globals;
8282
#endif
8383

8484
/* Pretend it still exists */
85-
#if PHP_VERSION_ID >= 70100
8685
# define ZEND_AST_LIST ((1 << (ZEND_AST_IS_LIST_SHIFT + 1)) - 1)
87-
#endif
8886

8987
extern const size_t ast_kinds_count;
9088
extern const zend_ast_kind ast_kinds[];

tests/001.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function test(Type $arg = XYZ) : Ret {
2020
}
2121
PHP;
2222

23-
echo ast_dump(ast\parse_code($code, $version=50));
23+
echo ast_dump(ast\parse_code($code, $version=70));
2424
--EXPECT--
2525
AST_STMT_LIST
2626
0: AST_FUNC_DECL
@@ -38,7 +38,6 @@ AST_STMT_LIST
3838
name: AST_NAME
3939
flags: NAME_NOT_FQ (1)
4040
name: "XYZ"
41-
uses: null
4241
stmts: AST_STMT_LIST
4342
0: AST_IF
4443
0: AST_IF_ELEM

tests/array_destructuring.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Array destructuring
3-
--SKIPIF--
4-
<?php if (PHP_VERSION_ID < 70100) die('skip PHP >= 7.1 only'); ?>
53
--FILE--
64
<?php
75

@@ -15,7 +13,7 @@ list('foo' => $a, 'bar' => $b) = $x;
1513
[, [$a]] = $x;
1614
PHP;
1715

18-
echo ast_dump(ast\parse_code($code, $version=50));
16+
echo ast_dump(ast\parse_code($code, $version=70));
1917

2018
?>
2119
--EXPECT--

tests/array_destructuring_old.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ list($a, $b) = $x;
1111
list(, $b) = $x;
1212
PHP;
1313

14-
echo ast_dump(ast\parse_code($code, $version=50));
14+
echo ast_dump(ast\parse_code($code, $version=70));
1515

1616
?>
1717
--EXPECTF--

tests/assign_ops.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $a <<= $b;
2121
$a >>= $b;
2222
PHP;
2323

24-
echo ast_dump(ast\parse_code($code, $version=50)), "\n";
24+
echo ast_dump(ast\parse_code($code, $version=70)), "\n";
2525

2626
?>
2727
--EXPECTF--

0 commit comments

Comments
 (0)