Skip to content

Commit 83b21b5

Browse files
authored
Merge pull request #680 from emacs-php/feature/php81-readonly-keyword
Add PHP 8.1 readonly keyword
2 parents 4b0e9f8 + df84b7e commit 83b21b5

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

lisp/php-mode.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ PHP does not have an C-like \"enum\" keyword."
458458
php (append (c-lang-const c-class-decl-kwds) '("function")))
459459

460460
(c-lang-defconst c-modifier-kwds
461-
php '("abstract" "const" "final" "static" "case"))
461+
php '("abstract" "const" "final" "static" "case" "readonly"))
462462

463463
(c-lang-defconst c-protection-kwds
464464
"Access protection label keywords in classes."

tests/8.1/readonly.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
class Foo
4+
{
5+
private readonly string $p1;
6+
public readonly int $p2;
7+
8+
public function __construct(
9+
private readonly string $a1,
10+
public readonly int $a2,
11+
) {}
12+
}
13+
14+
__halt_compiler();
15+
16+
claas Err
17+
{
18+
/** Readonly property must have type */
19+
public readonly $e1;
20+
}

tests/8.1/readonly.php.faces

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("
4+
5+
")
6+
("class" . php-class-declaration)
7+
(" ")
8+
("Foo" . font-lock-type-face)
9+
("
10+
{
11+
")
12+
("private" . php-keyword)
13+
(" ")
14+
("readonly" . php-keyword)
15+
(" ")
16+
("string" . font-lock-type-face)
17+
(" ")
18+
("$" . php-variable-sigil)
19+
("p1" . php-variable-name)
20+
(";
21+
")
22+
("public" . php-keyword)
23+
(" ")
24+
("readonly" . php-keyword)
25+
(" ")
26+
("int" . font-lock-type-face)
27+
(" ")
28+
("$" . php-variable-sigil)
29+
("p2" . php-variable-name)
30+
(";
31+
32+
")
33+
("public" . php-keyword)
34+
(" ")
35+
("function" . php-keyword)
36+
(" ")
37+
("__construct" . php-function-name)
38+
("(
39+
")
40+
("private" . php-keyword)
41+
(" ")
42+
("readonly" . php-keyword)
43+
(" ")
44+
("string" . font-lock-type-face)
45+
(" ")
46+
("$" . php-variable-sigil)
47+
("a1" . php-variable-name)
48+
(",
49+
")
50+
("public" . php-keyword)
51+
(" ")
52+
("readonly" . php-keyword)
53+
(" ")
54+
("int" . font-lock-type-face)
55+
(" ")
56+
("$" . php-variable-sigil)
57+
("a2" . php-variable-name)
58+
(",
59+
) {}
60+
}
61+
62+
")
63+
("__halt_compiler" . php-keyword)
64+
("();
65+
66+
")
67+
("claas" . font-lock-type-face)
68+
(" ")
69+
("Err" . font-lock-variable-name-face)
70+
("
71+
{
72+
")
73+
("/** Readonly property must have type */" . font-lock-doc-face)
74+
("
75+
")
76+
("public" . php-keyword)
77+
(" ")
78+
("readonly" . php-class)
79+
(" ")
80+
("$" . php-variable-sigil)
81+
("e1" . php-variable-name)
82+
(";
83+
}
84+
"))

tests/php-mode-test.el

+2-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ Meant for `php-mode-test-issue-503'."
659659

660660
(ert-deftest php-mode-test-php81 ()
661661
"Test highlighting language constructs added in PHP 8.1."
662-
(with-php-mode-test ("8.1/enum.php" :faces t)))
662+
(with-php-mode-test ("8.1/enum.php" :faces t))
663+
(with-php-mode-test ("8.1/readonly.php" :faces t)))
663664

664665
(ert-deftest php-mode-test-lang ()
665666
"Test highlighting for language constructs."

0 commit comments

Comments
 (0)