[Tex/LaTex] listings incorrectly highlights PHP keywords

listings

I have definitions as below:

\lstset{
    commentstyle = \color{gray},
    extendedchars = \true,
    inputencoding = utf8x,
    language = php,
    keepspaces = true,
    keywordstyle = \bfseries
}

And here's the code:

\begin{lstlisting}[language=PHP]
        function processRequest()
        {
            $req = $this->request;
            $view = $this->view;
            $view->addHeaderScript("scripts/jquery_addons.js");
            // doing smth...
            return $this->view;
        }

But only if, else and foreach keywords are highlighted. I want function and return keywords also to be highlighted.

Best Answer

function and return seem not to be in the PHP keyword default list (which can be found in the file lstdrvrs); you can add them using morekeywords:

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}

\lstset{language=PHP,
    commentstyle = \color{gray},
    extendedchars = \true,
    inputencoding = utf8x,
    keepspaces = true,
    keywordstyle = \bfseries,
    morekeywords={function,return}
}

\begin{document}

\begin{lstlisting}
        function processRequest()
        {
            $req = $this->request;
            $view = $this->view;
            $view->addHeaderScript("scripts/jquery_addons.js");
            // doing smth...
            return $this->view;
        }
\end{lstlisting}

\end{document}

enter image description here

Related Question