Archive: page 3
PHP and immutability: difficulties and scalars - part one
Being a weakly typed dynamic language, PHP has not really had the concept of immutability built into it. We’ve seen the venerable define() and CONSTANTS of course, but they’re limited. Whilst PHP does ship with an immutable class as part of it’s standard library, DateTimeImmutable, there is no immediately obvious method to create custom immutable objects. This article is part of a series I have written on the topic of immutability in PHP code: Read more โ
Alter a MySQL column in all databases
When you have a series of applications all running the same database structure it can be annoying to roll out schema updates across all the databases. If you’ve got migrations then great - script their deployment, but when you’re dealing with an old legacy application you probably don’t have the luxury. I was firmly in the latter class of devops when working on a project a couple of years ago so I wrote a handy little snippet of SQL to help me out. Read more โ
Email me when the file changes
It is important to ensure that Google does not index sites whilst they are still on a staging environment, but you cannot lock it down completely - how would your clients proof it? So I run a simple global rewrite rule in Apache that redirects all requests for robots.txt to a central disallow all response. This works great and Google appears to honour the rule as one would hope. What happens though when something about that central file changes? Read more โ
SQL style guide misconceptions
Many people have read, reviewed and even implemented the SQL style guide that I wrote. This is great, but there have also been a number of commonly held misconceptions or incorrect readings of the points made in the guide. I have decided to address some of the more common ones via a blog post that will, hopefully, clarify the situation. Basics A lot of people seem to have a very weird understanding of the basic terms used in the guide so here is what I mean when I say ‘Avoid’ and ‘Try’: Read more โ
Quick way to create a PHP stdClass
A very short and simple trick for creating new stdClass objects without having to set every property individually. This is akin to JavaScript’s object notation, but not quite as elegant. Creating a new object in JavaScript looks like the following example. const x = { a: "test", b: "test2", c: "test3", }; With PHP it is possible to use type casting to convert a simple array into a stdClass object which gives you a similar looking syntax although there is a little more typing required. Read more โ
Functional Programming in PHP Second Edition Available Now
It is with great pleasure that I announce the second edition of the Functional Programming in PHP book that I have been working on. There is twice the content of the first edition of the book as well as updates for PHP 7 and Facebook’s HHVM (HipHop Virtual Machine). There are now more functional techniques and patterns included with pipelines, pattern matching and flat maps among them. I have added a section of the book dedicated to the handy syntax and functionality that HHVM can provide functional programmers with. Read more โ
Importing and aliasing PHP functions
As a follow on to my short post about namespaces and functions from a year ago I thought it would be worth covering importing a specific function and aliasing functions via namespace operators too. This has been possible since PHP 5.6, but there is a nice addition in PHP 7 I’ll cover towards the end. In the previous article I demonstrated how you can namespace functions and use them, but as a refresher; you can enclose functions within a namespace just like a class. Read more โ
Installing pgmodeler on Ubuntu
Pgmodeler is a handy tool for designing databases with an ERD style interface specifically aimed at the PostgreSQL community. It can come in a couple of different ways, but I am going to covering the self build process here. So if you want to learn how to build and install pgmodeler read on! To be able to build anything you’ll need to install the tools from Ubuntu’s repositories. sudo apt-get install gcc libxml2-dev postgresql The first dependency you will need to install is the from QT5 UI toolkit. Read more โ
I’ve finally found some time to look at my old remote control car again - I was so happy when I bought it as a kid nearly twenty years ago. I’ve still got the original nickel cadmium battery (all 1300mAh!) and charger so I charged it up expecting that there’d be little to no response from the car. Amazingly the kids and I got about 5 minutes of full throttle action out of it before it slowed to a halt. Read more โ
Way back in 2007 I arrived in London, England ready to start a new chapter of my life working in the big city. I’d left a good job at a web agency in Melbourne - one of the world’s most livable cities - to experience the financial capital of Europe. It was a fantastic time and so much happened I could write a novel, but here are a few highlights. Read more โ