PHP Logo

The Splat Operator In PHP

5th August 2020 - 6 minutes read time

The PHP splat operator (...) has been available in PHP since version 5.6. When it was introduced I made note of it but have never really used it, so I thought it might be interesting to explore it a little.

Internally, the ellipsis operator in PHP is called T_ELLIPSIS, although I have heard a few different names for the operator in the past. This includes names like:

  • Ellipsis
  • Unpacking operator.
  • Packing operator.
  • Three dots operator
  • Spread operator
  • Splat operator

Personally, I think the splat is the correct name for this operator, so I'll be using that from now on.

PHP Logo

Using PDO To Create A Data Access Object

4th August 2020 - 14 minutes read time

A Data Access Object (DAO) is a way of taking data out of a database or API and present it in a unified way across your application. As a design pattern this has uses in standardising how a particular bit of data is passed around, without having to resort to using arrays to accomplish the same job.

I was doing some work with PHP's PDO library the other day when I noticed that I could fetch data out of a database using the fetchAll() method with the PDO::FETCH_CLASS flag. This flag automatically returns the data in an object. This got me thinking more about how this worked, but I couldn't find many articles talking about this. Hence this post.

Setting Things Up

Let's take a class called SpecialText that will store an ID and some text, along with a __toString() method to allow the printing of those values. We will use this class throughout this post to store data from the database.

Drupal Logo

Drupal 8: Automated Spam Protection

24th July 2020 - 10 minutes read time

Spam is a constant problem for any site on the internet that has a publicly available form, but automatically preventing spam can be tricky. The idea is to prevent the automated spam bot from being able to submit data to your site, but not at the detriment of the users. There is a careful balance between preventing spam and prevent real content being submitted by real users. Manually moderating blog comments is usually a good idea, but many websites contain contact forms and user registration forms that are often targeted by spam bots.

Whilst Drupal does have a number of protections against cross site submissions or denial of service attacks and even has build in user and comment moderation. It does, however, need a little bit of help with preventing spam.

Drupal has a number of modules to deal with automated spam and they fall mainly into a number of different categories.

JQuery Logo

Inspecting And Reusing jQuery Events

19th July 2020 - 5 minutes read time

Adding events to HTML elements with jQuery is pretty simple, but I found that extending those events wasn't an easy task. I was faced with an issue where I had some third party code that performed an action on an element, and I needed to add an event and call the same handler from that event. As this was within a CMS I had limited scope to just add my new event to the existing code, so I needed a way of pulling out the current jQuery events and then calling that event handler separately. This post looks at how I accomplished this.

Let's start with a couple of simple form input elements.


<input type="text" class="field-text" />
<input type="text" class="field-next" />

As an example that can be useful here I'm going to set up a 'change' event that will copy the text entered into field-text into the field-next. This is a simple enough example and doesn't require that much code.

PHP Logo

PHP:CSI Get Price In Pence

17th July 2020 - 16 minutes read time

I was looking at some malfunctioning code the other day where the price was pulled out of one API service and sent to another API. The problem stemmed from the fact that the value coming out of the first API was as a string and the second API required the price in pence as an integer.

The difference in formats here meant that the number had to be converted from one format to another. During this process it was found that the value was sometimes out by a single pence.

For example, whilst the first API sent over a value of £20.40, the second API received a value of 2039, which is one penny out. This class did have some unit tests, but the tests but had failed to account for this rounding error.

As it turned out, this wasn't the only problem with the class in question, so I thought I would write up a quick PHP:CSI showing the problems and how I solved them.

#! code Logo

Keychron K2 Wireless Mechanical Keyboard: A Review

13th July 2020 - 9 minutes read time

I (like a lot of other people) recently started to work at home a lot more, and with a permanent desk setup at home I wanted a decent keyboard to work with. My work machine is a MacBook Pro 2018 and I dislike the keyboard quite a lot. It feels 'poppy', has some interesting key placements (the up and down arrows in particular), has no escape key or function keys at all.

Drupal Logo

Drupal PaaS Hosting Review: Dropsolid

13th July 2020 - 10 minutes read time

Continuing my review of some Drupal PaaS hosting platforms I am taking a look at Dropsolid.

What I'm not doing is a massive deep dive on all platforms. Ultimately, your milage will vary and what you get out of these platforms will be different for most people. You will know the requirements of your project and what you need to accomplish.

Also, if you want to know more about a platform, then please contact them directly. I'm sure they will be happy to hear from you.

Based in Gent, Belgium, Dropsolid is a Drupal development agency who have built a Drupal hosting platform. The Dropsolid Experience Cloud is a platform built from years of experience in hosting and maintaining Drupal.

I met a few of the team at DrupalCamp London 2020 and they were kind enough to supply me with a key to evaluate the platform.

Drupal Logo

Drupal PaaS Hosting Review: Platform.sh

10th July 2020 - 9 minutes read time

Continuing my review of some Drupal PaaS hosting platforms I am taking a look at Platform.sh.

What I'm not doing is a massive deep dive on all platforms. Ultimately, your milage will vary and what you get out of these platforms will be different for most people. You will know the requirements of your project and what you need to accomplish.

Also, if you want to know more about a platform, then please contact them directly. I'm sure they will be happy to hear from you.

Platform.sh is a PaaS site created by Commerce Guys, who are the main driving force being the Drupal Commerce suite of modules. They split off in 2016 and have grown to become a very respectable company in the PaaS space. They have also expanded their service to support a lot more than Drupal so you can easily deploy your Drupal and WordPress sites side by side.

Drupal Logo

Drupal PaaS Hosting Review: Pantheon

8th July 2020 - 11 minutes read time

Continuing my review of some Drupal PaaS hosting platforms I am taking a look at Pantheon.

What I'm not doing is a massive deep dive on all platforms. Ultimately, your milage will vary and what you get out of these platforms will be different for most people. You will know the requirements of your project and what you need to accomplish.

Also, if you want to know more about a platform, then please contact them directly. I'm sure they will be happy to hear from you.

Pantheon provides a PaaS solution started in 2010 in the USA. They now have a worldwide support staff and have data centres in a variety of different locations throughout the world. They started out as a specialist Drupal host, but now have support for WordPress hosting solutions.

Drupal Logo

Drupal PaaS Hosting Review: Acquia

2nd July 2020 - 12 minutes read time

I've been looking at Drupal hosting solutions recently, and after trying a few I thought I would write a quick review of each. I was specifically looking for hosting providers that provide dedicated Drupal hosting support and an administration dashboard of some kind. It turns out that a handful of such suppliers exist. Whilst it is perfectly possible to setup a server on AWS or DigitalOcean and then install Drupal there, this isn't what I am looking at. The good thing about Platform as a Service (PaaS) solutions is that you get hosting, backup, recovery, logging, tools, and analysis all built in. Some platforms even have extra tools like build pipelines, marketing systems or analytics.