PHP

PHP is already strictly typed

PHP is already strictly typed, in the same way that JavaScript is. Not through the language itself, but with the help of tooling. JavaScript achieves this through tools like Typescript. (I use typescript as an example, as that is what i normally use.) Typescript adds a lot of new syntax to tha language, which allows for type checking. The transpiler then simply won’t transpile if there are type errors( depending on your configuration).

The modern PHP developers toolbox

The tools a modern PHP developer needs to strive.

Running Homestead from a separate directory

When creating a PHP website, there is a good chance that you wish to use a virtual machine. This has many benefits, like managing multiple versions of php, or extensions etc. A lot of projects use vagrant in combination with virtual box. But nobody likes to set up a Vagrantfile every single time. Laravel created homestead, which deals with all the vagrant configuration for you. You can install it in your project with composer install laravel/homestead, and you got it.

What is a default object?

What is a clean solution to display a ‘default’ message to the user, when something they try to access isn’t there (anymore)? We could let the our repository throw an exception, catch it somewhere, and then let our controller handle it. Maybe we could return null, and pass that all the way up and add a fall back message for the content in the view somewhere? Why not try a better solution and work with a default object.

Noop polyfills

A while ago a reddit post showed up, where someone installed version 9.99.99 of paragonie/random_compat. Seeing a package update from 2.* to 9.99.99 may be a bit confusing, but given how autolaoding, polyfills and composer work in php, this is actually quite a clever way of dealing with things. Lets take a look at version constraints, autoloading and composer to see why.

Infection 0.9 is out!

I wrote about infection a while ago, and not too long after that, 0.9.0 was released. Lets look at the new features, and how we can use them in our projects!

PHP will lose its LTS

In about 5 months PHP 5.6 loses its security support. Which means that in 5 months, PHP loses its current Long Term Support(LTS) version. If you don’t count security only support as LTS, then PHP hasn’t had an LTS for the past 1.5 years. If your website can’t handle PHP 7 or higher, you may start finding it harder to get support for that, with hosting sites like acquia removing php 5.6 support We will look at the advantages, and disadvantages of LTS, and what it means for the PHP ecosystem.

Automated code reviews

Sometimes a code base has specific code style rules, that aren’t easy to detect with either with a style fixer or a static analyzer. So instead of having to tell every new contributor your rules during a PR, or lay them all out in your CONTRIBUTING.md, why not automatically check them with PHPUnit. We will look at a couple of different ‘rules’ your code base could have, and how to set up the automated tests.

The case against case

Chances are you have written a switch case statement or two. Aren’t they much ‘cleaner’ than a bunch of if else statements? Today i would like to convince you that using switch case, in modern php, is a bad practice.

PHP extensions, polyfills and you

A little while ago someone ran into an error with a dependency of a project i worked on. A fatal error, which seemingly only occurred for them: the ctype_alnum function was not defined. So it turned out the ctype functions aren’t part of the php core, but are instead a ‘default’ extension. Lets explore what extensions mean for your project, and how to help your users with these kinds of errors.