Friday, May 18, 2007

1 ThingI Like About PHP

I was never a big fun of scripting languages. I hate not knowing what type of objects I'm working with. However, dynamic typing does have its advantages. A guy from work points out that using dynamic typing, it's very easy to write mocked objects for unit tests.
In Java, C# or any other strongly typed languages, you'll have to mocked the entire interface in order to use it. If an interface has 100 functions (by the way, if you do have 100 functions in 1 class, you should consider refactoring), you'll have to implement all 100 functions to create a concrete class. With PHP, you can create a class that's not even in the same hierarchy as the interface and only implement the functions that you are interested in. As long as the function signatures match the ones in the interface, PHP will invoke them.
So the first thing I like about PHP is the ease of writing mocked object using dynamic typing.

No comments: