The Fix is In (for Effortless Ctags' PHP Comment Parsing Bug)

by Daniel Convissor at 2015-09-22 09:31:00

A bug in Exuberant Ctags 5.8 causes comments in PHP files to be parsed. When comments contains the word function, the subsequent word is parsed as the name of a function. This can wind up filling the Tag List view with meaningless entries. Below is a demonstration of the problem and instructions on how to get the fix by installing ctags from source.

First, let's see the problem. Copy this first code block into a script named example.php:

<?php
/**
 * ctags 5.8 parses this function incorrectly by not
 * ignoring the word function inside comments
 */
function real_function() {}

Install the default ctags package available at the moment, 5.8:

sudo apt-get install exuberant-ctags

And parse the file:

ctags -f ./tags example.php

This screen shot shows incorrectly and inside in the tag list on the left:

Fortunately, one day after 5.8 was released, jafl committed revision 729 to fix the problem. Here's how to obtain that on your system:

UPDATE: I just learned of the Universal Ctags project, an actively maintained fork of the Exuberant Ctags code base. Use these instructions to install ctags. Skip the following code block, which is only here for historical purposes.

# See UPDATE note, above.

# DON'T EXECUTE THE COMMANDS IN THIS BLOCK

# Get rid of 5.8.
sudo apt-get remove exuberant-ctags

# autoconf is needed to assemble the configure files
sudo apt-get install autoconf autoconf-doc

svn checkout svn://svn.code.sf.net/p/ctags/code/trunk/ ctags

cd ctags
autoconf
./configure
make

sudo make install

Time to re-parse the file using the repaired version of ctags:

ctags -f ./tags example.php

Voila! The only thing in the tag list is real_function.

Tags: ctags, vim, php

View all posts

Email me a comment:

(I'll append it here when I get a chance.)