Skip to content

Commit 64ea727

Browse files
rlerdorfclaude
andauthored
Support PHP 8.6 (#259)
# Support PHP 8.6 Add compatibility shims in php_ast.h for the internal Zend API changes in PHP 8.6: - `ZEND_AST_METHOD_REFERENCE` was renamed to `ZEND_AST_TRAIT_METHOD_REFERENCE` - The `_throw()` ZPP variants were removed; plain ZPP now always throws, so `zend_parse_parameters_throw` maps to `zend_parse_parameters` and the removed `ZEND_PARSE_PARAMS_THROW` flag is defined to `0` (the throwing default). All guarded on `PHP_VERSION_ID >= 80600`, so older versions are unaffected and the userland `ast\AST_METHOD_REFERENCE` constant is unchanged. ## New 8.6 feature: doc comments on parameters Of the implemented PHP 8.6 RFCs, only [Add DocComments for function parameters](https://wiki.php.net/rfc/parameter-doccomments) is a parser change that affects the AST; the rest are library functions, new built-in enums, and reflection/runtime/ini/stream changes that don't touch the parse tree. `AST_PARAM` already has a `docComment` child (index 4), which was always `null` before 8.6. It is now populated by the parser for parameters carrying a doc comment, with no extension changes required. The output matches the engine's own `ReflectionParameter::getDocComment()` (including the before-vs-after-parameter comment behavior), and older AST versions are unaffected. `tests/php86_param_doc_comments.phpt` is added as a version-gated regression test (skips on PHP < 8.6), covering doc comments on both function parameters and property-hook parameters. ## CI There is no published `php:8.6` docker image yet, so 8.6 could not be added to the previous docker-based test matrix. CI now uses `shivammathur/setup-php` for all PHP versions (7.2–8.6) in a single matrix, replacing the docker-based setup. 8.6 is built from php-src master and marked `continue-on-error` since it is still in development and is a moving target. The `package.xml` validation previously run in `ci/test_inner.sh` is preserved as a `pecl package` step, and the now-unused `ci/` docker scripts are removed. --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 5e0feb4 commit 64ea727

6 files changed

Lines changed: 135 additions & 53 deletions

File tree

.github/workflows/main.yml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,32 @@ jobs:
2222

2323
# See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-environment-variables-in-a-matrix
2424
strategy:
25+
# 8.6 is built from php-src master, so a failure there should not cancel
26+
# the other versions.
2527
fail-fast: false
2628
matrix:
27-
include:
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).
30-
- PHP_VERSION: '7.2'
31-
- PHP_VERSION: '7.3'
32-
- PHP_VERSION: '7.4'
33-
- PHP_VERSION: '8.0'
34-
- PHP_VERSION: '8.1'
35-
- PHP_VERSION: '8.2'
36-
- PHP_VERSION: '8.3'
37-
- PHP_VERSION: '8.4'
38-
- PHP_VERSION: '8.5'
29+
# NOTE: Quoted so the yaml parser does not turn e.g. 8.0 into the number 8.
30+
PHP_VERSION: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6']
3931

4032
# Steps represent a sequence of tasks that will be executed as part of the job
4133
steps:
4234
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
4335
- uses: actions/checkout@v2
4436

45-
# Runs a single command using the runners shell
46-
- name: Build and test in docker
47-
run: bash ci/test_dockerized.sh ${{ matrix.PHP_VERSION }}
37+
- name: Setup PHP
38+
uses: shivammathur/setup-php@v2
39+
with:
40+
php-version: ${{ matrix.PHP_VERSION }}
41+
tools: pecl
42+
43+
- name: Build
44+
run: |
45+
phpize
46+
EXTRA_CFLAGS='-Wall -Wextra -Wno-unused-parameter' ./configure
47+
make -j2
48+
49+
- name: Test
50+
run: NO_INTERACTION=1 REPORT_EXIT_STATUS=1 make test TESTS="--show-diff"
51+
52+
- name: Verify package.xml is valid
53+
run: pecl package

ci/Dockerfile

Lines changed: 0 additions & 13 deletions
This file was deleted.

ci/test_dockerized.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

ci/test_inner.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

php_ast.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ extern ast_str_globals str_globals;
9999
# define ZEND_AST_CLONE 0x1fc
100100
#endif
101101

102+
#if PHP_VERSION_ID >= 80600
103+
/* ZEND_AST_METHOD_REFERENCE was renamed to ZEND_AST_TRAIT_METHOD_REFERENCE. */
104+
# define ZEND_AST_METHOD_REFERENCE ZEND_AST_TRAIT_METHOD_REFERENCE
105+
/* The _throw() ZPP variants were removed; plain ZPP now always throws.
106+
* ZEND_PARSE_PARAMS_THROW is gone, so a flag of 0 yields the throwing default. */
107+
# define ZEND_PARSE_PARAMS_THROW 0
108+
# define zend_parse_parameters_throw zend_parse_parameters
109+
#endif
110+
102111
/* Pretend it still exists */
103112
# define ZEND_AST_LIST ((1 << (ZEND_AST_IS_LIST_SHIFT + 1)) - 1)
104113

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
--TEST--
2+
Doc comments on function/method parameters (PHP 8.6+)
3+
--SKIPIF--
4+
<?php if (PHP_VERSION_ID < 80600) die('skip PHP >=8.6 only'); ?>
5+
--FILE--
6+
<?php
7+
8+
require __DIR__ . '/../util.php';
9+
10+
$code = <<<'PHP'
11+
<?php
12+
function f(
13+
/** doc for $a */
14+
int $a,
15+
$b,
16+
/** doc for $c */
17+
string $c = "x",
18+
) {}
19+
20+
class C {
21+
public string $p {
22+
set(
23+
/** doc for $value */
24+
string $value
25+
) { $this->p = $value; }
26+
}
27+
}
28+
PHP;
29+
30+
echo ast_dump(ast\parse_code($code, $version=120)), "\n";
31+
--EXPECT--
32+
AST_STMT_LIST
33+
0: AST_FUNC_DECL
34+
name: "f"
35+
docComment: null
36+
params: AST_PARAM_LIST
37+
0: AST_PARAM
38+
type: AST_TYPE
39+
flags: TYPE_LONG (4)
40+
name: "a"
41+
default: null
42+
attributes: null
43+
docComment: "/** doc for $a */"
44+
hooks: null
45+
1: AST_PARAM
46+
type: null
47+
name: "b"
48+
default: null
49+
attributes: null
50+
docComment: null
51+
hooks: null
52+
2: AST_PARAM
53+
type: AST_TYPE
54+
flags: TYPE_STRING (6)
55+
name: "c"
56+
default: "x"
57+
attributes: null
58+
docComment: "/** doc for $c */"
59+
hooks: null
60+
stmts: AST_STMT_LIST
61+
returnType: null
62+
attributes: null
63+
__declId: 0
64+
1: AST_CLASS
65+
name: "C"
66+
docComment: null
67+
extends: null
68+
implements: null
69+
stmts: AST_STMT_LIST
70+
0: AST_PROP_GROUP
71+
flags: MODIFIER_PUBLIC (1)
72+
type: AST_TYPE
73+
flags: TYPE_STRING (6)
74+
props: AST_PROP_DECL
75+
0: AST_PROP_ELEM
76+
name: "p"
77+
default: null
78+
docComment: null
79+
hooks: AST_STMT_LIST
80+
0: AST_PROPERTY_HOOK
81+
name: "set"
82+
docComment: null
83+
params: AST_PARAM_LIST
84+
0: AST_PARAM
85+
type: AST_TYPE
86+
flags: TYPE_STRING (6)
87+
name: "value"
88+
default: null
89+
attributes: null
90+
docComment: "/** doc for $value */"
91+
hooks: null
92+
stmts: AST_STMT_LIST
93+
0: AST_ASSIGN
94+
var: AST_PROP
95+
expr: AST_VAR
96+
name: "this"
97+
prop: "p"
98+
expr: AST_VAR
99+
name: "value"
100+
attributes: null
101+
__declId: 1
102+
attributes: null
103+
attributes: null
104+
type: null
105+
__declId: 2

0 commit comments

Comments
 (0)