
- Image via Wikipedia
After the previous post in this series, additional independent implementations of the idea of JavaScript-style classes have turned up. So I’m going to list them and comment briefly on the differences. I hope this will be helpful to anyone who actually wants to use this in practice and needs to decide on the details of the implementation. Here are the links in chronological order:
- Ionut G. Stan:Javascript style PHP with PHP 5.3.0 (forum posting).
- Fredrik Holmström: Javascript-OO & Python-DuckTyping in PHP5.3.
- John Mertic: What’s new in PHP V5.3, Part 2: Closures and lambda functions.
- My own previous article.
- Andrea Giammarchi: A JavaScript Object Like PHP Class.
One difference is how JavaScript-like the implementations are. Some of them implement a syntax that is deliberately made to resemble JavaScript. Andrea Giammarchi’s version even uses ArrayAccess to make it possible to access object properties using both object and array syntax, as in JavaScript. At the other extreme is my implementation. I’ve tried to make it as similar to a regular PHP class as possible. You can instantiate an object in the same way as with an ordinary PHP class. This comes from defining the methods inside the class constructor.
After seeing all of these, I prefer my own way of doing it, except that it lacks what I mentioned in the previous article: an exception when you try to call an unrecognized method. But I’m obviously not objective, and I may have have missed something.
[...] his blog today Dagfinn Reiersol has posted the next part of his “real programming with PHP 5.3″ series looking at links. After the previous [...]