Shiphp The PHP Developer's Guide

Try/Catch Blocks in PHP

When things go wrong within your program it’s a good idea to handle the failure gracefully in some way. One of the best ways to deal with exceptions is by using a try...catch block. Let’s take a look at how this works. The Basics First let’s look at the success case — in other words when an exception is not thrown: <?php try { echo "... Read more

Using Docker to Run a PHP and MySQL Application

One of the most common operations for any application is to connect to a database, but installing multiple databases locally can be a tricky process. You have to make sure everyone on your team has the right version and that they’re connecting the same way. Fortunately, Docker makes this really simple and more transferrable. 1. Write a PHP Sc... Read more

Environmental Variables in PHP and Docker

Environmental Variables in PHP and Docker When running a PHP application, you almost always want to keep some environmentally dependent variables stored outside of your codebase. For example, it’s not a good idea to hard-code your database connection information because then you will have to remember to switch between local and production det... Read more

Interview with Mahmoud Zalt, Creator of Laradock

In the process of writing Building PHP Applications in Docker, I ran across a number of great tools and resources for PHP developers who want to get started using Docker. One tool that I’ve since started using for some of my side projects is Laradock, a docker-based development environment for PHP applications. Many PHP developers are used to v... Read more

Conditional Operators in PHP

Like any programming language, PHP supports conditional statements to execute specific blocks of code if a statement is true (or false) or some condition is met. If you’re familiar with conditional statements in other programming languages PHP should give you no trouble, but there are a couple lesser-known operators (ternary and null coalescin... Read more

Installing PHP Packages with Docker and Composer

Package management is a method for importing code (often from open source libraries) and keeping dependencies up to date in a software development project. In PHP, we have a couple ways to manage packages, but the dominant choice for modern PHP development is Composer. While you can install PHP and Composer on your local machine directly, in ... Read more

Introduction to Classes in PHP

Like most object-oriented programming languages, classes are the backbone of PHP projects. Classes allow you to group code into logical pieces, reuse code, and prevent misuse of functions and variables. This post will focus on the mechanics of classes and not the underlying concepts in object oriented software design. If you are interested in... Read more

Making Your First Website with PHP

In order to build a working website on your computer that is powered by PHP, you’ll need to first have PHP installed and know some basic HTML. In this tutorial we will make a website that displays variables written in PHP code to users in an HTML document. Let’s get started! Open a text editor and create a file called index.html Add the ... Read more

Introduction to Loops in PHP

In programming, we use loops to iterate over data. This can be useful for transforming individual elements in an array, validating input data, sorting, and many other things. PHP offers several methods for looping over data arrays. “for” Loops The for loop offers space for up to three parameters: the initial value, the condition, and the inc... Read more

Writing Functions in PHP

Functions are one of the basic building blocks of any programming language. They allow you to define blocks of code that can be called many times in many places throughout your program. Functions are great for reusability, but they also help make code more concise and easier to read. Let’s look at some examples. Using built-in PHP functions ... Read more