More accurate alternative/workaround to ctags/Cscope for PHP?

To improve ctags for PHP, you could create tags file like this:

#!/bin/bash
cd /path/to/framework/library
exec ctags-exuberant -f ~/.vim/mytags/framework \
-h ".php" -R \
--exclude="\.svn" \
--totals=yes \
--tag-relative=yes \
--PHP-kinds=+cf \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'

then load the tags

:set tags=~/.vim/mytags/framework

taken from my blog post


As a C++ developer I had similar issues for a long time. Until, that is, I reorganized my approach to using tag files under Vim a few years ago. The trick that made it work for me was to generate separate tag files for different slices of code: my project, various external code libraries, etc... I then had to set the 'tags' option to look for the files in a priority order, with my local code project files coming first and then working outward from there with the system header files being LAST.

In my case, I had separate tag files for each of these and listed in this order in the 'tags' option:

  1. My local project
  2. Any other project that this project uses
  3. System-bundled libraries (boost)
  4. System-bundled libraries (WxWidgets)
  5. System libraries (C++ standard libraries)
  6. System libraries (all else)

I'm not a PHP developer, but again the main mistake I made for a long time was just generating a single tags file FOR EVERYTHING. I'd have upwards of 30 tags to search through many times (using the :tag command). If you generate multiple tags files you have much more control over the search order of tags and thus what tags in which files are found.

See if that works for you. It did for me.