From 66e062a158d0913178bca24f6cd8adffccf37c96 Mon Sep 17 00:00:00 2001
From: USAMI Kenta <tadsan@pixiv.com>
Date: Sat, 10 Mar 2018 01:10:07 +0900
Subject: [PATCH 1/2] Add test for #439

GitHub-Issue: #439
---
 php-mode-test.el          |  4 ++++
 tests/issue-439.php       | 33 ++++++++++++++++++++++++++++++
 tests/issue-439.php.faces | 42 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 tests/issue-439.php
 create mode 100644 tests/issue-439.php.faces

diff --git a/php-mode-test.el b/php-mode-test.el
index 32753fce..9f9a343a 100644
--- a/php-mode-test.el
+++ b/php-mode-test.el
@@ -914,6 +914,10 @@ style from Drupal."
       (set-auto-mode)
       (should (not (eq 'php-mode major-mode))))))
 
+(ert-deftest php-mode-test-issue-439 ()
+  "Various heredoc/nowdoc formats are highlighted appropriately."
+  (with-php-mode-test ("issue-439.php" :faces t)))
+
 (ert-deftest php-mode-test-type-hints ()
   "Test highlighting of type hints and return types."
   (with-php-mode-test ("type-hints.php" :faces t)))
diff --git a/tests/issue-439.php b/tests/issue-439.php
new file mode 100644
index 00000000..8ca36676
--- /dev/null
+++ b/tests/issue-439.php
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * GitHub Issue:  https://github.com/ejmr/php-mode/issues/439
+ */
+
+$a = <<<ABC
+Let'go Justin
+ABC;
+
+$b = <<<A_B_C
+Let'go Justin
+A_B_C;
+
+$c = <<<'A_B_C'
+Let'go Justin
+A_B_C;
+
+$d = <<<"A_B_C"
+Let'go Justin
+A_B_C;
+
+$e = <<<いろは
+Let'go Justin
+いろは;
+
+$f = <<<'いろは'
+Let'go Justin
+いろは;
+
+$g = <<<"いろは"
+Let'go Justin
+いろは;
diff --git a/tests/issue-439.php.faces b/tests/issue-439.php.faces
new file mode 100644
index 00000000..61f716c1
--- /dev/null
+++ b/tests/issue-439.php.faces
@@ -0,0 +1,42 @@
+;; -*- mode: emacs-lisp -*-
+(("<?php" . font-lock-preprocessor-face)
+ ("\n\n")
+ ("/**\n * GitHub Issue:  " . font-lock-doc-face)
+ ("https://github.com/ejmr/php-mode/issues/439" link font-lock-doc-face)
+ ("\n */" . font-lock-doc-face)
+ ("\n\n")
+ ("$" . php-variable-sigil)
+ ("a" . php-variable-name)
+ (" = ")
+ ("<<<ABC\nLet'go Justin\nABC" . php-string)
+ (";\n\n")
+ ("$" . php-variable-sigil)
+ ("b" . php-variable-name)
+ (" = ")
+ ("<<<A_B_C\nLet'go Justin\nA_B_C" . php-string)
+ (";\n\n")
+ ("$" . php-variable-sigil)
+ ("c" . php-variable-name)
+ (" = ")
+ ("<<<'A_B_C'\nLet'go Justin\nA_B_C" . php-string)
+ (";\n\n")
+ ("$" . php-variable-sigil)
+ ("d" . php-variable-name)
+ (" = ")
+ ("<<<\"A_B_C\"\nLet'go Justin\nA_B_C" . php-string)
+ (";\n\n")
+ ("$" . php-variable-sigil)
+ ("e" . php-variable-name)
+ (" = ")
+ ("<<<いろは\nLet'go Justin\nいろは" . php-string)
+ (";\n\n")
+ ("$" . php-variable-sigil)
+ ("f" . php-variable-name)
+ (" = ")
+ ("<<<'いろは'\nLet'go Justin\nいろは" . php-string)
+ (";\n\n")
+ ("$" . php-variable-sigil)
+ ("g" . php-variable-name)
+ (" = ")
+ ("<<<\"いろは\"\nLet'go Justin\nいろは" . php-string)
+ (";\n"))

From c4169993cddb16deb6bcd618f375081849e6ac30 Mon Sep 17 00:00:00 2001
From: USAMI Kenta <tadsan@pixiv.com>
Date: Sat, 10 Mar 2018 01:11:31 +0900
Subject: [PATCH 2/2] Fix #439 heredoc syntax probrem

Syntax of heredoc/nowdoc is here.
http://php.net/manual/language.types.string.php#language.types.string.syntax.heredoc
---
 php-mode.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/php-mode.el b/php-mode.el
index 2e23642e..70e7efc1 100644
--- a/php-mode.el
+++ b/php-mode.el
@@ -934,13 +934,13 @@ this ^ lineup"
 
 (eval-and-compile
   (defconst php-heredoc-start-re
-    "<<<\\(?:\\w+\\|'\\w+'\\)$"
+    "<<<\\(?:\\_<.+?\\_>\\|'\\_<.+?\\_>'\\|\"\\_<.+?\\_>\"\\)$"
     "Regular expression for the start of a PHP heredoc."))
 
 (defun php-heredoc-end-re (heredoc-start)
   "Build a regular expression for the end of a heredoc started by the string HEREDOC-START."
   ;; Extract just the identifier without <<< and quotes.
-  (string-match "\\w+" heredoc-start)
+  (string-match "\\_<.+?\\_>" heredoc-start)
   (concat "^\\(" (match-string 0 heredoc-start) "\\)\\W"))
 
 (defun php-syntax-propertize-function (start end)