Ways to code PHP

May 29th, 2008

Prolog: In the last few years, I wrote PHP code mostly within Notepad. At some point I felt a strong desire for syntax highlighting and a structured source tree and therefore I am still exploring the possibilities.

As the first real need was syntax highlighting, I ended up using SciTE first. It is pretty much a more extended Notepad with the ability to highlight PHP code via a syntax highlight definition that ships with it. However, SciTE has too many different half-working highlight definitions and seems not to like wide pages so that scrolling to a far-right-away position in the middle of a line is somewhat painful. Maybe they fixed this already, but the last version I used still did so. There is also no source tree for a project folder.

Afterwards I read about Textmate, a much praised editor for Mac and I liked the screenshots/screencasts (my first from the Ruby “A blog in 15 minutes” buzz). It comes with a source tree view and pretty syntax highlighting. Unfortunately it is a commercial Mac only product and if you own one, you will pretty sure already know about it.

Not much later, E – Texteditor, which claimed to be Textmate for Windows, appeared and I gave it a try. In fact it was not hard to set it up using a really nice look and it was much fun to use it. However, there is no php documentation available directly from the editor – ok, it’s not an IDE, it’s an editor. In the first releases there were some bugs and there still seem some to be left especially when quickly closing and reopening E, but I can recommend this editor to everyone who has $ 34,95, wants a very pretty editor and currently misses syntax highlighting and a source view. Imho E is the best Notepad replacement for editing PHP code available on Windows and it can also do much more.

On Linux, gedit is an excelent tool that also ships with gnome. It’s basically the same like E but does not look so pretty. However, editing PHP files with it does just work and there has been some progress recently to make PHP highlighting more comfortable. You may need to tweak it a little to fit your needs, but because you are using Linux, I assume you know where to find more information on this :P.

Not long ago I also noticed Netbeans’ approach to PHP editing and because I have been using Netbeans for a long time to write Java already, it was a must to try it out. At the first look it is just good old Netbeans as you know it from Java but the Early Access for PHP edition features PHP only instead including code completition and so on. Unfortunately creating a new project from existing source folders is not yet trivial and there are some settings that you will never need without appserver integration. However it is possible to create a new project just by using the default settings, steal the “nbproject” directory from it, copy it to the root folder of your PHP app and edit the “project.properties” and “project.xml” to fit your needs. For example:

C:\yourapp\nbproject\project.properties:
copy.src.files=false
copy.src.target=
include.path=\
    ${php.global.include.path}
index.file=index.php
source.encoding=UTF-8
src.dir=C:\\yourapp
url=http://localhost/yourapp_path_maybe

C:\yourapp\nbproject\project.xml:
<?xml version=”1.0″ encoding=”UTF-8″?>
<project xmlns=”http://www.netbeans.org/ns/project/1″>
    <type>org.netbeans.modules.php.project</type>
    <configuration>
        <data xmlns=”http://www.netbeans.org/ns/php-project/1″>
            <name>YourappName</name>
        </data>
    </configuration>
</project>

Done so, when opening the project (just the root folder of your app) you are presented with your PHP application loaded inside Netbeans with all your files in the source tree view. From now on you can edit your project easily and, if you setup a local webserver (take a look at Server2Go or Lighty2Go if you want a small but just working local webserver/mysql/php stack), get live results. For serious PHP programming (yes, not everyone acknoledges this ^^) the free Netbeans for PHP is a nice tool. I am looking forward to see the next releases. Till then I will use it for a while and hope that it will become simpler to use in the future without all the bloat :).

There is also a PHP plugin available for integration with Eclipse (this is also official supported by Zend) but because I never were the typical Eclipse guy (don’t know, just not the way I like things to look / be done), I did not test this in much detail. As far as I read the Eclipse PDT will integrate somewhat deeper with PHP thus featuring a debugger and easy integration with the Zend Framework. As I’m still a Notepad-Era guy running his own framework code, this may not be exactly what I am looking for (I also complained about the somewhat forced appserver integration in netbeans which is quite the same, you remember). However, if you plan to use most of the features of a complete IDE supported by the Zend guys, Eclipse PDT will be your way to go currently.

<?php die(“So far…”); ?>

2 Responses to “Ways to code PHP”

  1. Markus Says:

    I was for a long time very satisfied with UltraEdit, which is not really targeted at any language. Due to the debug abilities however, we switched here internally to PHPed – maybe something for you as well. It is quite powerful in debugging code, as you can f.e. stop the code at a certain line and check all vars set, etc.

    greetings,

    Markus ( Polarbaer )

  2. daniel Says:

    Nice to read you again, ol’ friend. I’ll definitely give it a look next time I’m unsatisfied with E. However, till now I did not have a need for the debugging stuff within an IDE. Probably I never will.

Leave a Reply