MoiDev

Another blog about software development

How to Use Emacs to Work With PHP

php-mode

Php mode is an emacs major mode design to work with php. The principal functions that add to emacs are:

  • Syntax hightlighting
  • PHP comments
  • Search in PHP documentation
  • Browse the PHP online manual
  • Movements between statements

Sincerely this functions are very few in comparation with other programming modes of emacs, therefore I go to explain more modes to solved this.

php mode in github

flymake-phpcs (PHP_CodeSniffer)

Flymake mode is an Emacs mode that allows you to run continuous syntax checks against the current buffer “While U Type”. PHP_CodeSniffer is a static analysis tool for PHP that can be configured to produce a wide range of warnings and errors according to various customizable coding standards. Emacs-flymake-phpcs glues the two together, giving you continuous static analysis as you edit.

This minor mode allows to check the correct php style with phpcs application. It is a very intersting and util mode because it allows us see in real time the errors in own code and a description to fix it.

Currently I have configurated this mode to check the PSR0, 1 and 2 standards.

Github repository of flymake-phpcs

CodeSniffer

YASnippet

YASnippet is a template system for Emacs. It allows you to type an abbreviation and automatically expand it into function templates. Bundled language templates includes: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more. The snippet syntax is inspired from TextMate’s syntax, you can even import most TextMate templates to YASnippet. Watch a demo on YouTube or download a higher resolution version

Yasnippet is a powerful minor emacs mode, is very popular and is a tool to use snippets like creation of classes, functions, use php (or another language) functions with parameters and more things.

To use this mode with PHP we need the php snippets, we’ll found this code in this github repository. YAsnippet

Geben

GEBEN is a software package that interfaces Emacs to DBGp protocol with which you can debug running scripts interactive. At this present DBGp protocol are supported in several script languages with help of custom extensions.

Geben is a complete mode to debug PHP code with xdebug.

Geben

Another useful modes to work with PHP

  • Autocomplete Autocomplete text.
  • sf-el Mode to simplify the use of Symfony2 (created by me and free to colaborate ;) )
  • Fill column indicator Show a vertical line in the maximun column. Important if you follow the PSR standards with flymake

If you are interested I share my .emacs file here and a installation scripts to my modes.

About my English

My first language is the spanish, the reason that I write it in english is I want to learn. Please for any mistake or posible correction write a comment in the post. Thank you.

Comments