The odd bit

Once is an accident, twice is a coincidence, three times is an enemy action.

The odd bit - Once is an accident, twice is a coincidence, three times is an enemy action.

The quest for a PHP editor

I’ve had a hate-and-love relationship with a few editors over the past few years, but I’ve never found one that I truly love. Some look promising in the beginning but after some time I really get tired of their limitations.

I thought I had settled with Eclipse (with PDT) because it’s the best I’ve used, but the software update messes up so often it’s not funny anymore. That and those pesky “builders” that keep flagging stuff as errors in places where they’re absolutely useless. So with Eclipse rapidly losing credit I started a new search… without any results so far.

Perhaps my requirements are too steep, but Visual Studio [1] manages to combine them so I don’t think they’re too far-fetched. What I want in a PHP editor (or rather IDE):

  • Projects instead of loose files (think of: Visual Studio solutions or Eclipse projects).
  • Smart intellisense (not just autocomplete, it should be able to parse the project and recognize custom classes – Visual Studio is the reference here).
  • Handle whitespace properly (tabs to spaces, clear trailing whitespace per line, clear empty lines).
  • Formatting (with bonus points if I can configure my own set of rules).
  • A non-cluttered modern interface.

Extra bonus points are awarded to IDEs that can perform small “design-time” checks (e.g. unreachable code, non-returning branch, unused variables, …) and have a couple of refactoring functions/shortcuts (to name two: rename variable/method and implement interface).

So if there’s anyone who knows about a little gem for PHP development, please let me know. Oh, and don’t make me beg 😉

[1]: No, there’s nothing wrong with your eyes. Visual Studio is actually a Microsoft product that I like. It’s simply the best IDE in my very humble opinion.

HOWTO: Feed Component

Version 2007.1beta1 of the eZ Components has been released earlier this week. This release features a beta version of the Feed component. The downside is that there is almost no documentation available about this component, but I’m sure that is just a temporary situation that will be resolved before the final release.

Anyway, programmers are a bit like adventurers: to boldly go where no one has gone before. It would be a shame to keep this adventure for myself, so what follows is a small and simple tutorial that will show you how you can display items from an external feed.

Continue reading

Enhanced Selection Datatype v2.0

I have some good news for the fans of the Enhanced Selection datatype for eZ publish: version 2.0 is in the works. The new version will contain some shiny new features, but it will also be completely rewritten from scratch. The code of the currently released version is almost ancient and a rewrite will make it easier to add new features (and of course, bring it more up to date with eZ standards).

It’s possible that class content and/or object content won’t be compatible between the two versions, but in that case I will make an upgrade script to ease the transition. I do aim for the fact that current object-level templates won’t need to be changed for the new version.

Another issue is eZ publish version compatibility. The latest stable release is 3.9.x and both the 3.6 and 3.7 series have had their end-of-life bugfix release which means they’re unsupported as of now. My plan is to support version 3.8 and newer. My guess is that this is not such a big problem for 3.7 users (the new version will most likely be compatible, just not supported). The real problem will most likely be 3.6 and older releases, mainly due to the fact that they’re based on PHP 4.3. If I go for 3.8+, I cannot guarantee it’ll be compatible with the PHP 4.3 series. And that’s the reason for this post – and I’ll only say it once:

If you want 3.6 support, speak now or remain silent forever. Now where did I hear that before? 😉

Object/Relational Data Persistence in PHP

Another post about PHP and the topic is once again data persistence. I’m starting to wonder if this is my search for the Holy Grail…

I previously blogged about some differences in the implementations of the Zend Framework and the eZ components. Let it be clear, the Zend Framework’s implementation is also not the most logical one.

Something they have in common is that neither can cope with composite keys. No biggie you’d think until you encounter two entities with a many-to-many relationship. While there are ways to circumvent that problem, I’d rather have it working without trickery.

The real oddity in the Zend Framework comes when you start working with results from database fetches. The persistence starts by defining a PHP class that extends Zend_Db_Table. A fetch from that table results in an object of the Zend_Db_Table_Rowset class. Iterating over that object results in objects of the Zend_Db_Table_Row class. This means that one row from the database is not an instance of the persistent class. The real drawback of that implementation comes when you want to define custom properties on “persistent objects”.

An example of such a custom property: artists and songs. Each artist is an object of the Artist class. Instead of having to load the Song table yourself and query it for all songs of Artist A, it would be a lot handier if you could access all songs by using a property, e.g. $artist->songs.

If you would like to achieve such a thing with the Zend Framework, you have to start implementing your own extended Zend_Db_Table_Row classes and making sure all results are casted to the new type. Not good. Another possibility would be to implement something in the persistent class (the table’s class), but that’s even less logical.

So here I am… once again in search of a good implementation. Looking back at things, the data persistence implementation that ships with eZ publish is not that bad after all. Anyways, I hereby call upon the world to leave a comment if you know of any other data persistence implementations for PHP5.

P.S.: I’ve tried looking at Symfony, but I found its installation to be too cumbersome at the time (not to mention that I couldn’t download a required library). So there’s no need to mention that one.

Zend Framework (PHP)

I’m currently working on a website for myself using the Zend Framework. Actually, it’s take #3 of the project. The first attempt never had a chance of succeeding even remotely. The second attempt was much better, but the pieces of the puzzle didn’t really fit together.

The biggest problem I experienced while working on the second attempt was the data persistence implementation of the eZ components. It’s really not convenient to work with: you must implement at least two functions (even though the API doesn’t force you to implement them) to manually return the data that should go into the database and to set object properties to values from the database. You also need to create a definition file that maps properties to database fields. Hey, if there’s a mapping, why do I still need to implement manual getting/setting in the class? Another major shortcoming is that a table’s primary key must be an auto-increment integer.
Data persistence is a lot easier in the Zend Framework. All you need to do with your class is extend the Zend_Db_Table class, follow a couple of naming conventions and it works! If you really want to be a difficult guy, you can override the naming conventions.

That’s the biggest difference I’ve encountered so far. There will probably be follow-ups to this post as I continue to dig deeper in the Zend Framework.