PHP PHP
From time to time I see bugs in the code and I start thinking "really? is it possible that no one noticed that bug before? am i the first person to see this code?". I thought it might be worth writing a little post on what helps me to deal with bugs and software quality in general and what are the common pitfalls in developer's thought process. Although it is not a very extensive post i hope it may inspire some developers to try new approaches :-)
In general it is extremely rare for me to commit bugs that would make it into production (maybe less than one a year? hard to say as it is really rare). To be honest I can't remember a serious issue with my code for last 5 years.
Unfortunately i have to support PHP 5.2 and i also need to run my Mac in 32 bit mode as my VPN client does not support 64 bit :(
This causes quite a lot of hassle as PHP 5.2 is less and less supported by frameworks, extensions etc. It is also waste of time as i have to manually build stuff instead of using regular packages, ports etc.
Here is a quick step by step guide on how to get mongodb and PHP5.2 mongo pecl extension going on your MacOSX in 32bit mode!
NOTE: 32 bit mongodb binaries have 2GB address space limit so you wont be able to process too much on your laptop. You will still be able to code and connect to remote instances just fine.
There are many ways to implement mobile version of your website but easiest and probably cleanest one is to use mobile subdomain.
Once you have your mobile website you want to implement an automated test suite to be able to regression test the functionality after every release. You also want the test suite to be easy to configure and run it against test environment. In perfect world you want the test suite to run as part of the continous integration setup. Jmeter allows for all of that and is free. As a huge fan of jmeter i recommend you download it and play around with it as soon as possible.
In this article I describe how to create a test suite for mobile website redirects, you can also download my jmeter test plan and customise it to test your own websites.
Lets make something clear from the very start: JUST BECAUSE THERE IS https:// IN THE URL OF THE REMOTE SERVICE IT DOES NOT MEAN THE CONNECTION IS SECURE!
I am sorry for the tone of this post but i am enraged by how popular this issue is online. If you ask why i suggest a little experiment.
Steps to follow
- Change your host file settings to point something like www.somedomain.com to your development server
- Create a self signed certificate for this domain and setup a https virtual host to serve it on local IP or alias
- Put a test file on that URL
I have been thinking a bit recently how to manage dependencies and how to structure Zend Framework based applications to make the code less coupled, more testable and less dependent on the global scope.
I don't mean to be negative but I am not too happy about the web application structure that most articles and books present. In Zend Framework world controller seems to be the place when things get done. Controller is the workhorse and this is where all the logic seems to be buried. It also seems to me that model in MVC is reduced to database integration but there is no services layer for some reason. Where ever you look you will see the same examples with controller doing all the work and models being simple Zend_Db_Table or Zend_Db_Table_Row instances. You will not see business logic focused classes, Controller or DB Model, thats all you can choose from.

I think it is not a really bad book as it provides quite a good introduction to Zend Framework. Especially with a lack of any good Zend Framework literature i guess it may be still worth to read it.
I would not recommend it to people who work with Zend Framework already. You will probably not find a lot of new information in it. If you are starting your journey with Zend Framework or with MVC in general i guess you may benefit from the book quite a lot.
Book also provides some nice foundation for the CMS design. So if you decided that Drupal is not good enough and you want to spend months writing your own CMS then you may want to check out this book :)
I saw a post recently and it got me thinking, should constructor of a child class follow the signature of its parent? My gut feeling was telling me it should not really matter. Constructor is not part of the Interface nor part of the public API that object exposes (not a class).
On the other hand i like the rule of least surprise and I like to have arguments in same order across the API (if it makes sense).
Author suggests that it is a good idea to use same arguments lists in exceptions derived from \Exception. I don't really think its a bad idea i am just wondering does it have anything to do with inheritance as the article suggests (i think the argumentation is not very accurate in this case).
Google APIs are one of the best that is not a secret but seems like Google Maps are even nicer and easier to use in the 3rd version. I just had a look on the APIs last Thursday night and noticed that a few things are even better than before. Let me show a simple example and a few easy features you can use to put a Google map on your website in a matter of an hour!
It is funny how often you can get caught by surprise that PHP is not Java. I have been using type hints in PHP for a long time but somehow i did not came across that for a long time.
If you have a method that type hints the parameter you wont be able to pass null in as in PHP null is not just unknown value but it is also a type.
It is a bit frustrating that i have to use mac and can not just use the same system that we have in production but well, that is the standard now. So to make the best of it you have to adapt and learn how to deal with operating system issues ;)
I found it a bit tricky to compile PHP extensions like PECL memcache or whatever on my mac for a few reasons. My mac comes with PHP 5.3 and i need to run my site on 5.2 that i got from MAMP. In addition i have 64 bit system that runs PHP in 32 bit mode so i have to tell compiler to use 32 bit mode only.
Just a very short tip as it was a big surprise to me :) If you have xdebug enabled SoapClient will not throw an exception but cause a fatal error.
All you have to do is disable xdebug or make sure that soap service is available.
Few days ago i had to write a groovy test for a java class and i had a long chain of calls to mock. I was not sure how to test it nicely and i started wondering is there a nicer way to do it in PHP. Usually in PHP there is a nice way to do almost anything :D
I have been working on a little piece of code on the weekend lately and i thought it would be useful to have a numeric range similar to Groovy's range. Maybe there is such code already but quick google search did not give me anything useful so i hacked it together myself.
Later on I thought maybe it would be worth sharing it so here it is.
I know it is obvious but i guess people still ignore the fact that documentation and knowledge sharing is important. Through my career as developer (so far 8 years) i have not joined a single project nor company that would have a proper up to date documentation. As a result it takes half year to catch up, instead of 3 months, for every new person joining the team and it causes constant headaches. I believe that could be improved if there was proper high / mid level documentation.
I know, I know, all the 'lazy developers' will jump and scream "but you should not waste time on documentation! code should document itself!". Well great, should IP addresses, web services, database schemas also document themselves? Being lazy is not a virtue, even that it seems to be cool.
I can not believe it how many times did i stumble upon these stupid UTF-8 BOMs. At work we actually have a script which is part of the build cycle and makes sure we do not have any UTF-8 BOMs in our files.
First of all Byte Order Mark is a set of bytes at the beginning of a file that is added to indicate what unicode encoding is inside of the file. The only problem is that it does not matter for UTF-8 because UTF-8 does not have problem of byte order issues! Some editors and tools keep on adding UTF-8 BOM and it takes time to figure it out! oh man does it!?