Shiphp The PHP Developer's Guide to Docker

Latest Blog Posts

Introduction to Writing Unit Tests in PHP with PHPUnit and Docker

Testing your code is a great way to improve quality and minimize bugs due to regression. PHP has a couple frameworks available for unit testing, but the most popular by far is PHPUnit. Because unit tests are going to be run on a variety of environments, running tests within Docker containers can make tests faster and more portable. This tutori... Read more

Switch Statements in PHP

While the switch statement isn’t as popular as conditional operators like if and elseif in PHP, it can still be useful when evaluating a number of possible outcomes. Using a switch statement is pretty simple, so let’s look at an example: <?php $var = rand(0,2); switch($var) { case 1: echo "The magic number is one."; bre... Read more

Running a PHP Application with Postgres and Docker

MySQL may be the standard choice in relational databases for PHP developers, but Postgres is a great option as well. The setup is very similar, and running Postgres and PHP within Docker containers is just as easy. 1. Create a PHP Script that Connects to Postgres Let’s start by writing a simple PHP script that will connect to a Postgresql da... Read more

Introduction to Interfaces and Abstract Classes

Object oriented languages like PHP have many tools for layering objects. Among PHP’s tools are interfaces and abstract classes which can be used in similar ways. I think many new developers tend to get confused and misuse them, so I’m hoping a little tutorial here will help. What is an Interface? An object interface in PHP is like a class te... Read more

Array Functions in PHP

Arrays are an important and widely used type in PHP. They are essentially ordered maps that allow developers quick access to key-value storage in their applications. For some basic array examples, see my previous post of working with arrays in PHP. PHP has over 75 array functions to help you manipulate and use arrays more efficiently. Since t... Read more