SwiftlyTilting: usability, reusability

Thursday, February 10, 2011

An unexpected PHP quirk

The other day when I was doing work for a new client, I ran into a very strange error. I was configuring their Mediawiki site, but whenever I added code to the configuration file, it would cause a fatal error. Unfortunately the site’s error logs were not available to me. Initially I was baffled, though with some trial and error I was able to discover the problem. It was very minor and would have been discovered instantly if I had access to the error log, but it revealed an interesting quirk of the PHP engine, specifically: PHP does not require a closing semicolon at the end of the last line of the PHP script.

I was trying to add new configuration lines, and was baffled why any valid code except comments would cause an error. I eventually discovered that lines added at the top of the file worked correctly, and worked my way down the file to find which line was causing the error. Once I knew which line was causing the problem, the error was quite obvious, but until then, I had been baffled!

In a proper development environment where you have access to error logs, this will never be an issue, but when working “blind”, this is an unusual quirk that can cause some very unexpected and confusing results.


Hah, yeah I noticed the same a while back, though I was showing somebody how important the ; was and tried to show him what happened when you forget one… which was nothing… (As you guessed, I removed the last one)

Comment by Johan — Friday, February 11, 2011 @ 7:19 am

^ haha :D

Comment by swiftlytilting — Friday, February 18, 2011 @ 7:45 pm

Validate XHTML | Word Press