Professional PHP Blog

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.

Dependency Injection in PHP

June 26th, 2006

The June issue of PHP Architect is out. My column this month is on dependency injection, a topic which I’ve been warming up to lately.

First there was CORBA. Then insane complexity of CORBA was supplanted by the intolerable complexity of EJB. Influenced by an agile mindset and the power of Unit testing, a group of java programmers began to construct simpler alternatives to EJB. Thus, the inversion of control frameworks were born. Martin Fowler came along, clarified and renamed the pattern dependency injection. This activity has originated in the Java world, but the pattern applies in PHP as well.

It is heartening to see an industry solve a problem over the course of a decade, moving from complex vendor driven middle-ware to simple patterns. The thing I like most about DI is how dead simple it really is.

Fowler’s article is a must read on the topic. However, I have two problems with most of the introductions to dependency injection. One is the use of irrelevant girl kisses boy style examples. The other is the over-emphasis on the container. The whole point of dependency injection is to move away from invasive component architectures, such as EJB. From my point of view, it is far more interesting to explore what impact dependency injection has on your design than what features your container has.

With that in mind, I tried to write an introduction to dependency injection that avoiding talking about DI containers and that tried to use real, relevant examples. For an example, I started with a typical, run of the mill dependency, torn from a popular PHP library that shall remain nameless, but easy to guess. Then I build on that with a plug-able backend in a common PHP style and then again using dependency injection.

For me dependency injection is relatively new territory, but one that I feel is an important technique. I’d like to see this technique become more widespread in PHP, especially in the current crop of frameworks.

I have a significant bias, but I think you should read the article. I hope you find it useful.

25 Comments »

Programming Language Trends via Google

May 10th, 2006

There is a new google toy as of today: Google Trends. So of course, I wanted to see how PHP is faring on the trendy landscape. Here is a comparison of PHP, Java, C#, and Perl:

PHP, Java, C# and Perl
PHP Java C# Perl

PHP seems to be holding steady, or slightly declining. But, Java is waning, as I discussed in Why isn’t PHP the natural successor to Java?. C# seems to be steady and slightly increasing, while Perl is steady and slightly decreasing. So where are those Java programmers going if not PHP? Are they going to Ruby and Ruby on Rails?

Java, Ruby and Ruby on Rails
Java Ruby Ruby on Rails

It looks like Ruby and Ruby on Rails are tiny fish in Java’s pond. Perhaps those Java developers are going to C# or one of Microsoft’s unsearchable variants. It would be interesting to see the MSN search trends. However, there is one area where Ruby on Rails seems to be doing well:

Struts vs. Ruby on Rails
Struts Ruby on Rails framework

It used to be that most of the PHP frameworks were cloning Struts. Now they clone Rails. There is an increasing interest in frameworks.

There are countries where PHP is more popular. Here is the PHP vs. Java chart for the Netherlands. Right at the end, PHP beats out Java. Search, Derick. Search.

Java vs PHP in the Netherlands
PHP Java

One last Trend. What is trendier that Ajax these days? Certainly not JavaScript.

Java vs PHP in the Netherlands
Javascript AJAX

Notice how Javascript searches are declining while Ajax is ascending. Strangely I would have thought that the interest in AJAX would have created an increase in Javascript searches. It doesn’t look like the total search volume of the two terms together is increasing that much. Looking at the news volume graph is striking. The AJAX press release machine is in full gear. So is AJAX the thing that everyone is talking about, but nobody is doing? Can you say Web 2.0 bubble?

Please use the AJAX enabled comment form below to tell me how wrong I am.

DISCLAIMER: These graphs and conclusions are for entertainment purposes only. Opinions expressed should not be construed as trendy advice. The particulars of any person’s concerns and circumstances should be discussed with a qualified trend spotting practitioner prior to making any decisions.

29 Comments »

PHP Games

April 6th, 2006

Earlier this morning, I ran across the Heroes of might and magic online mini-game (via digg). The game is written in PHP and uses the prototype and scriptaculous java script libraries. The interface is very drag and drop oriented and it uses Ajax to update game status. The graphics are very good. No flash as far as I can tell.

Their server is getting crushed right now, intermittently not responding and running out of MySQL connections. The javascript crashed my browser a couple times. Still, I was intrigued by the combination of Ajax and PHP and I liked the interface. Definitely one to bookmark for later. (I’d like to track down that crasher when I get more time.)

What is the state of Ajax games? of PHP games? Are there other PHP/Ajax games that I should bookmark?

79 Comments »

The Coding Apprentice

March 29th, 2006

Ok, maybe I watch too much reality TV, but I’d like to see a show called “The Coding Apprentice.”
Starting with 18 candidates, each week, they are randomly divided into teams of 2, 3, or 4 (perhaps solo on odd weeks). Then a charity is selected with a need for an application. Each team [...]

50 Comments | Read the full post »

php|architect Test Pattern

March 21st, 2006

The March issue of php|architect came out yesterday. I’m excited to see this issue finally out. I’ve taken over writing the monthly Test Pattern column from Marcus Baker and this issue contains my first column.
Writing doesn’t come easy to me. Writing this blog for the past two years has helped me improve. [...]

9 Comments | Read the full post »

James Gosling on PHP

March 11th, 2006

James Gosling, the “father of Java,” recently commented on PHP:

“PHP and Ruby are perfectly fine systems,” he continued, “but they are scripting languages and get their power through specialization: they just generate web pages. But none of them attempt any serious breadth in the application domain and they both have really serious scaling and performance [...]

7 Comments | Read the full post »

Extreme Simplicity

March 1st, 2006

Could this be the manifesto of “Extreme Simplicity?”

10 fundamental rules for the age of user experience technology:

More features isn’t better, it’s worse.
You can’t make things easier by adding to them.
Confusion is the ultimate deal-breaker.
Style matters
Only features that provide a good user experience will be used.
Any feature that requires learning will only be adopted by a [...]

14 Comments | Read the full post »

Comparing PHP with other languages

February 9th, 2006

Chris Shiflett posted some thoughts on PHP and Ruby on Rails which has generated some interesting discussion. Chris divides programming languages into two categories:

Flexible and powerful: PHP, C, C++, and Perl.
Structured and organized: Java, Ruby, and ASP.NET.

I don’t disagree with the cultural grouping. PHP’s cultural heritage is definitely in the Unix programming, C/Perl [...]

43 Comments | Read the full post »

Hump Day Blues

February 1st, 2006

I’m in a foul mood today. What good is having a blog if you can’t rant a bit?

To doctor X: We had an appointment at 11am. You called and asked us to change it to 10am. We were your first patient of the day, we came at 10 and you didn’t see [...]

10 Comments | Read the full post »

The Evolution of Design Patterns

January 31st, 2006

Rebecca Wirfs-Brock suggests that it may be time for the GoF Design Patterns book to be refreshed. She points out that the C++ and graphics programming examples may be less relevant to today’s C# and Java programmers. She implies that state of the art has advanced in the twelve years since the book [...]

9 Comments | Read the full post »

« Previous Entries
Next Entries »
    Subscribe Feed
    Share Subscribe to this blog…
    Share Bookmark or share this page…
  • About

    My name is Jeff Moore. I'm a PHP programmer living in San Francico and working for a startup.

    More about me…

  • Categories

    • Agile Methods (14)
    • Mac (14)
    • Misc (18)
    • Open Source (14)
    • PHP (99)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • The Legality of Republishing RSS Feeds  28
      Tory Rennemeyer, eenicker, Reverse Phone Lookup [...]
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  258
      Tuan Lal, Lavagem de estofados, Edward L. Kind [...]
    • php | tek 2008  36
      how to mend ice machine, Akademija Debelih, Odbacena [...]
    • goto in PHP  59
      kasor, Thomas Valdivieso, Murray Ziadie [...]
    • Firefox Extensions for Web Developers  33
      kasor, Website Design Toronto, mobila bistrita [...]
    • Why PHP is easier to learn than Java  68
      kasor, Justina Calvery, Guy Lipton [...]
    • Meta Tag Refresh Faux Paux  43
      html email templates, E-Juice Reviews, image [...]
    • Improved Error Messages in PHP 5  49
      Carroll Tina, Przeprowadzka, Emery Harari [...]
    • Benchmarking PHP's Magic Methods  33
      kayu oyunlar?,dora,oyun,oyna, Benjamin Bejjani, paypal website [...]
    • Microbenchmarks of single and double qouting.  24
      kefir grains minneapolis, sexshop dildo, tuim688 [...]
  • My Other Stuff

    • Lively Debate
      My blog on Politics and non-technical topics
    • Web Application Component Toolkit
      PHP MVC Framework
  • Other PHP Blogs

    • Dynamically Typed
    • Jason E. Sweat
    • John Lim
    • Marco Tabini
    • Marcus Baker
    • Norbert Mocsnik
    • PHP Patterns
  • Site

    • Archives
    • Log in
  • Search