#php

blog

PHP Traits: Multiple Inheritance Revisited

When I first wrote about my hacky TypeScript multiple inheritance implementation that destroyed a codebase, I included a small (emphasis on small) section about multiple inheritance in C++, mostly as a joke about how complicated my TypeScript solution was becoming. I was, however, unaware of PHP’s approach to the concept, so I thought I should write an addendum to that piece. PHP, while primarily functional, does boast object-oriented capabilities that have only improved over time. One of these (added in PHP 5.4!) is Traits, which allow you to compartmentalize code into modules added arbitrarily to classes. Traits are essentially small
Read More
blog

The Terrible, Horrible, No Good, Very Bad PHP Stock Functions

A lot of defenders of PHP will say that the language has improved immensely in later versions with better support for OOP, which it has! However, PHP is fundamentally broken in its implementations of its stock functions, even compared to other dynamically-typed languages such as JavaScript. Let’s look at some examples: PHP – Functions of a String Function Prefix String is first parameter? Descriptive Name explode ❌ ❌ Sorta ord ❌ ❌ ❌ strstr str ✅ ❌ str_pad str_ ✅ ✅ substr ❌ ✅ ✅ There’s a great amount of inconsistency here, especially with how the functions are named. For
Read More
blog

Implementing WebP Conditionally

What is WebP? We use a lot of images when we build websites nowadays, and while some might disagree with this, I doubt it’s going anywhere. As a result, we have to invest a lot of work into optimizing those images as much as possible, often resorting to ugly and dated compression techniques. WebP is a new image format designed by Google for the modern web. According to a Google study, the average WebP file size is 25-34% smaller than a JPEG equivalent . What’s the Catch? The advantages of WebP seem obvious: lower file sizes with a negligible change
Read More