php_ast/version.rs
1use std::fmt;
2
3/// The PHP language version that code is parsed or printed for.
4///
5/// When set in `php_rs_parser::ParseOptions`, the parser reports syntax that
6/// requires a higher version. The AST is still produced (the parser recovers),
7/// so callers can always inspect what was parsed.
8///
9/// Ordering is meaningful: `Php82 > Php81`, etc.
10///
11/// Defaults to [`PhpVersion::Php85`], the latest released version.
12#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
13#[non_exhaustive]
14pub enum PhpVersion {
15 /// PHP 7.4 — arrow functions, typed properties, spread in array expressions, numeric literal separator.
16 Php74,
17 /// PHP 8.0 — match, named arguments, constructor promotion, union types, nullsafe `?->`, throw expression, `mixed`/`false`/`null` types.
18 Php80,
19 /// PHP 8.1 — enums, `readonly` properties/parameters, intersection types, first-class callables, `never` type.
20 Php81,
21 /// PHP 8.2 — `readonly class` (also `abstract readonly class`), DNF types, `true` type.
22 Php82,
23 /// PHP 8.3 — typed class/enum constants.
24 Php83,
25 /// PHP 8.4 — property hooks, asymmetric visibility.
26 Php84,
27 /// PHP 8.5 — pipe operator (`|>`), `clone` with property overrides, `final` promoted properties,
28 /// asymmetric visibility on static properties.
29 #[default]
30 Php85,
31 /// PHP 8.6 (unreleased) — partial function application (`?`/`...` call-argument placeholders).
32 Php86,
33}
34
35impl fmt::Display for PhpVersion {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 PhpVersion::Php74 => write!(f, "7.4"),
39 PhpVersion::Php80 => write!(f, "8.0"),
40 PhpVersion::Php81 => write!(f, "8.1"),
41 PhpVersion::Php82 => write!(f, "8.2"),
42 PhpVersion::Php83 => write!(f, "8.3"),
43 PhpVersion::Php84 => write!(f, "8.4"),
44 PhpVersion::Php85 => write!(f, "8.5"),
45 PhpVersion::Php86 => write!(f, "8.6"),
46 }
47 }
48}