Keep Your PHP Code Clean with Traits

In PHP object-oriented programming (OOP), inheritance means a class can only ever have a single parent, thus PHP is called a single inheritance language. Traits however give the ability for a class to inherit one or more sets of functions from different places and are a way around the single inheritance problem. Traits are sometimes referred to as mixins because they aren’t a class, more just a set of functions which get added to whatever uses that trait – and … Continued


Converting a Decimal to a Fraction in PHP

Below is a helper function to convert a decimal, like for instance 6.5, into a fraction, 13/3 in this example. In fact the function will return an array with the number on the top of the fraction (the numerator) being the first item and the number at the bottom (the denominator) being the second item. Edit 25th Nov 2016: Changed the function to be more accurate and added some phpunit tests for it. The Function: /** * Convert a decimal … Continued


Converting Google Maps Tile Coordinates to Boundary Box Coords

Usually working with the Google Maps API is a very simple and well documented experience. Saying this though, recently we wanted to overlay an image over the map. The overlay was relevant to the exact point which you were looking at, so the coordinates had to be exact. The images were also being retrieved from an external service, which we didn’t have access to change. The problem we were having stemmed from the fact that the Google Maps JavaScript library … Continued


New Go Learning Website – GolangCode.com

I’ve recently started a new site, helping with the basics of learning go. It’s not exactly a tutorial website, where every step of the how-to guide is explained to you, but more of a snippet repository – a starting point to working out how to do anything and everything which you might be looking at tackleing. This ranges from go routines to json encoding to file management to build processes. View GolangCode.com Photo by Brad Smith


Dedicated vs. Shared Databases: A ‘MySQL has gone way’ fix

While working on a data heavy web application recently we noticed some strange unstable performance with our SQL database – this is a post about how we investigated it and what we did about it. The application was written in PHP and hosted on Heroku in the EU region. We were using a ClearDB database, also hosted in the EU. TL;DR Our ‘MySQL server has gone away‘ message was fixed by moving from a shared database to a dedicated database … Continued


Super-charge your WordPress Blog: Setup a CDN

Performance is important. We get this. As blog owners if our users get frustrated then we get frustrated. In this post we’ll look at how you can move a blog’s performance and loading times to the next level. A couple of years ago we looked at how to improve a website’s loading times – this post should be more specific than that, focusing primarily on WordPress and how content is delivered to your users. Who is this article for? This … Continued


9 Things I Wish I’d Known about PHP Years Ago

I have been working with PHP for a good number of years now – (not including WordPress development, does that count? 😉 ). Here are some of the things I wish I’d known at the very beginning. Most of them are small little code snippets but there are also a few points about diving into the code too deep. Towards the end are a few helpful resources which have helped me out along the way. Coding: 1. Array Manipulation Since … Continued


Detecting if a User is on a Touch Screen Device in JS

Whilst recently working with native date pickers on mobile browsers, Chrome and Opera we came across an issue. The native datepicker wasn’t acting as we wanted – but we had no control over it (you can’t trigger a native datepicker to open in Chrome!). Because of this we wanted to fallback to a custom date picker (think jQuery UI) if a native date picker didn’t exist or if the browser is on a desktop. We’ll focus on the ‘is on … Continued


Validate a UK Grid Reference in Laravel 5

This will just be a small article and quite a specific one. We’ll be looking at how to verify an input to guarantee it is a valid 8 figure grid reference. This will be checking against the UK Ordnance Survey standard, so two letters followed by four easting numbers and four northing numbers. e.g. AA11112222 It is important to remove any spaces from the string before submitting. This can be achieved through a small JS function and a .replace function. … Continued


Create your own Exception Handler in PHP

If you’re used to writing your own PHP applications, you will no doubt be used to having to deal with exceptions being thrown at awkward moments. Resulting in a ugly 500 error being shown to the user and no extra direct from them to take. Luckily we can choose our own way of handling these exceptions, showing a better message or logging the error more efficiently. In an ideal world, we wouldn’t need these as everything would work perfectly, all … Continued


Direct Upload to S3 (using AWS Signature v4 & PHP)

The contents of this article has been replaced by a PHP Composer package, hope you find it useful.   View on Github This article is specifically about directly uploading files to S3 using the AWS Signature Version 4, which is mandatory for new S3 regions, like Frankfurt (EU). It will also become required on other regions at some point as Amazon migrate over, so it’s recommended to use this method where ever possible. For more info, you can read about … Continued


A Week with Laravel 5: What’s New

With a PHP project we have just started, we decided to begin development with the Laravel 5 framework – even before it’s been released. The framework is due to be released this month (Jan 2015) and instead of starting with Laravel 4 and attempting to migrate upwards, it seems natural to begin with the newest version even though it’s features might change slightly pre-release. Being comfortable developing with both PHP and Laravel 4, some of the changes with version 5 … Continued