diff --git a/php-face.el b/php-face.el index 75bdc81c..4230baeb 100644 --- a/php-face.el +++ b/php-face.el @@ -101,6 +101,11 @@ :group 'php-faces :tag "PHP Type") +(defface php-class '((t (:inherit font-lock-type-face))) + "PHP Mode face used to highlight class." + :group 'php-faces + :tag "PHP Class") + (defface php-constant '((t (:inherit font-lock-constant-face))) "PHP Mode face used to highlight constants." :group 'php-faces diff --git a/php-mode-test.el b/php-mode-test.el index 1a9177d6..6cd259f7 100644 --- a/php-mode-test.el +++ b/php-mode-test.el @@ -662,9 +662,10 @@ Meant for `php-mode-test-issue-503'." (goto-char (point-min)) (should (eq (php-mode-test-in-function-p nil) nil)))) -(ert-deftest php-mode-test-php74-arrow-fn () - "Test highlighting arrow funcsion (short closure syntax) added in PHP 7.4." - (with-php-mode-test ("7.4/arrow-function.php" :faces t))) +(ert-deftest php-mode-test-php74 () + "Test highlighting language constructs added in PHP 7.4." + (with-php-mode-test ("7.4/arrow-function.php" :faces t)) + (with-php-mode-test ("7.4/typed-property.php" :faces t))) (ert-deftest php-mode-test-lang () "Test highlighting for language constructs." diff --git a/php-mode.el b/php-mode.el index a339e17f..07edc7ea 100644 --- a/php-mode.el +++ b/php-mode.el @@ -1464,7 +1464,14 @@ a completion list." ;; namespaces ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face) ("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant) - + (,(eval-when-compile + (rx bol (* (syntax whitespace)) + (or "private" "protected" "public") + (+ (syntax whitespace)) + (group (? "?") (+ (or "\\" (syntax word) (syntax symbol)))) + (+ (syntax whitespace)) + (: "$" (+ (or (syntax word) (syntax symbol)))))) + 1 'php-class) ;; Support the ::class constant in PHP5.6 ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-magical-constant)) diff --git a/tests/7.4/typed-property.php b/tests/7.4/typed-property.php new file mode 100644 index 00000000..288defbe --- /dev/null +++ b/tests/7.4/typed-property.php @@ -0,0 +1,20 @@ +string = $var; + } + + public function print() + { + var_dump($this->string); + } +} + +(new Typed)->print(); diff --git a/tests/7.4/typed-property.php.faces b/tests/7.4/typed-property.php.faces new file mode 100644 index 00000000..18135538 --- /dev/null +++ b/tests/7.4/typed-property.php.faces @@ -0,0 +1,78 @@ +;; -*- mode: emacs-lisp -*- +(("" . php-object-op) + ("string" . php-property-name) + (" = ") + ("$" . php-variable-sigil) + ("var" . php-variable-name) + ("; + } + + ") + ("public" . php-keyword) + (" ") + ("function" . php-keyword) + (" ") + ("print" . php-function-name) + ("() + { + var_dump(") + ("$" . php-$this-sigil) + ("this" . php-$this) + ("->" . php-object-op) + ("string" . php-property-name) + ("); + } +} + +(") + ("new" . php-keyword) + (" ") + ("Typed" . font-lock-type-face) + (")") + ("->" . php-object-op) + ("print" . php-method-call) + ("(); +"))