1. Georg Brandl
  2. pygments-main
  3. Issues
Issue #829 new

PHP Lexer Improvements

info@josephcrawford.com
created an issue

When using pygments with jekyll I noticed that the lexer for PHP has a few issues with how code is highlighted.

In PHP when you have anything:: that is a static class call it could be anything::function( or anything::$property

This should be improved. Below is some HTML source for how my code is highlighted.

Code:
self::$_total_words_in_list = count( $lines );

Result:
<span class="nx">self</span>
<span class="o">::</span> <span class="nv">$_total_words_in_list</span>
<span class="o">=</span>
<span class="nb">count</span>
<span class="p">(</span>
<span class="nv">$lines</span>
<span class="p">);</span>

As you can see with the above output when you are using a function after an assignment operator it is highlighted properly. In the above you can see the count function is given the class 'nb' However notice that the self portion is given the class 'nx' and it should be getting the class 'nc'

I have also found an issue with the function name highlighting when you are not using it with an assignment operator. See the example below

Code:
$a = 10;
echo $a;
add($a);
echo $a;
addref($a);
echo $a;

Result:
<span class="nv">$a</span>
<span class="o">=</span>
<span class="mi">10</span>
<span class="p">;</span>
<span class="k">echo</span>
<span class="nv">$a</span>
<span class="p">;</span>
<span class="nx">add</span>
<span class="p">(</span>
<span class="nv">$a</span>
<span class="p">);</span>
<span class="k">echo</span>
<span class="nv">$a</span>
<span class="p">;</span>
<span class="nx">addref</span>
<span class="p">(</span>
<span class="nv">$a</span>
<span class="p">);</span>
<span class="k">echo</span>
<span class="nv">$a</span>
<span class="p">;</span>

In the example above notice how all of the function calls are not being highlighted rather they are being given a class of 'nx' for Name.Other These should be getting the proper class to highlight a function name.