   (if (or php-warned-bad-indent
           (php-check-html-for-indentation))
       (funcall 'c-indent-line)))
++
+(defconst php-tags '("<?php" "?>" "<?" "<?="))
+(defconst php-tags-key (regexp-opt php-tags))
+
+(defconst php-block-stmt-1-kwds '("do" "else" "finally" "try"))
+(defconst php-block-stmt-2-kwds
+  '("for" "if" "while" "switch" "foreach" "elseif" "catch all"))
+
+(defconst php-block-stmt-1-key
+  (regexp-opt php-block-stmt-1-kwds))
+(defconst php-block-stmt-2-key
+  (regexp-opt php-block-stmt-2-kwds))
+
+(defconst php-class-decl-kwds '("class" "interface"))
+
+(defconst php-class-key
+  (concat
+   "\\(" (regexp-opt php-class-decl-kwds) "\\)\\s-+"
+   (c-lang-const c-symbol-key c)                ;; Class name.
+   "\\(\\s-+extends\\s-+" (c-lang-const c-symbol-key c) "\\)?" ;; Name of superclass.
+   "\\(\\s-+implements\\s-+[^{]+{\\)?")) ;; List of any adopted protocols.
 
 ;;;###autoload
 (define-derived-mode php-mode c-mode "PHP"
   "Major mode for editing PHP code.\n\n\\{php-mode-map}"
-;;   (c-add-language 'php-mode 'c-mode)
-
-;;   (c-lang-defconst c-block-stmt-1-kwds
-;;     php php-block-stmt-1-kwds)
+  (c-add-language 'php-mode 'c-mode)
+
+;; PHP doesn't have C-style macros.
+;; HACK: Overwrite this syntax with rules to match <?php and others.
+;;   (c-lang-defconst c-opt-cpp-start php php-tags-key)
+;;   (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
+  (set (make-local-variable 'c-opt-cpp-start) php-tags-key)
+;;   (c-lang-defconst c-opt-cpp-start php php-tags-key)
+;;   (c-lang-defvar c-opt-cpp-start (c-lang-const c-opt-cpp-start))
+  (set (make-local-variable 'c-opt-cpp-prefix) php-tags-key)
+
+  (c-set-offset 'cpp-macro 0)
+  
+;;   (c-lang-defconst c-block-stmt-1-kwds php php-block-stmt-1-kwds)
+;;   (c-lang-defvar c-block-stmt-1-kwds (c-lang-const c-block-stmt-1-kwds))
   (set (make-local-variable 'c-block-stmt-1-key) php-block-stmt-1-key)
 
-;;   (c-lang-defconst c-block-stmt-2-kwds
-;;     php php-block-stmt-2-kwds)
+;;   (c-lang-defconst c-block-stmt-2-kwds php php-block-stmt-2-kwds)
+;;   (c-lang-defvar c-block-stmt-2-kwds (c-lang-const c-block-stmt-2-kwds))
   (set (make-local-variable 'c-block-stmt-2-key) php-block-stmt-2-key)
+
   ;; Specify that cc-mode recognize Javadoc comment style
   (set (make-local-variable 'c-doc-comment-style)
-    '((php-mode . javadoc)))
+       '((php-mode . javadoc)))
 
 ;;   (c-lang-defconst c-class-decl-kwds
 ;;     php php-class-decl-kwds)
   (set (make-local-variable 'c-class-key) php-class-key)
-
-  (defvar php-mode-syntax-table php-mode-syntax-table)
-  ;; this line makes $ into punctuation instead of a word constituent
-  ;; it used to be active, but it killed indenting of case lines that
-  ;; begin with '$' (many do).  If anyone has a solution to this
-  ;; problem, please let me know.  Of course, you're welcome to
-  ;; uncomment this line in your installation.
-;  (modify-syntax-entry ?$ "." php-mode-syntax-table)
-
-  ;; The above causes XEmacs to handle shell-style comments correctly,
-  ;; but fails to work in GNU Emacs which fails to interpret \n as the
-  ;; end of the comment.
-  (if (featurep 'xemacs) (progn
-                (modify-syntax-entry ?# "< b" php-mode-syntax-table)
-                (modify-syntax-entry ?\n "> b" php-mode-syntax-table)))
 
   (make-local-variable 'font-lock-defaults)
   (setq font-lock-defaults

      (goto-char here)
      (setq php-warned-bad-indent t)
      (lwarn 'php-indent :warning
	     "\n\t%s\n\t%s\n\t%s\n"
	     "Indentation fails badly with mixed HTML and PHP."
	     "Look for an Emacs Lisp library that supports \"multiple"
	     "major modes\" like mumamo, mmm-mode or multi-mode.")
      nil)))

(defun php-cautious-indent-region (start end &optional quiet)


  ;; PEAR coding standards
  (add-hook 'php-mode-pear-hook
            (lambda ()
              (set (make-local-variable 'tab-width) 4)
              (set (make-local-variable 'c-basic-offset) 4)
              (set (make-local-variable 'indent-tabs-mode) nil)
              (c-set-offset 'block-open' - )
              (c-set-offset 'block-close' 0 )) nil t)

  (if (or php-mode-force-pear
          (and (stringp buffer-file-name)
