Software Engineering in WordPress, PHP, and Backend Development

Tag: PHP (Page 5 of 12)

Using a Registry, Subscribers, and Services in WordPress

TL;DR: I find the using a registry, subscribers, and services very useful when building backend-centric plugins and utilities for WordPress. This post walks through how to do it.


After working in with design patterns, object-oriented programming, and WordPress for years, common ways of solving problems are bound to arise.

This is how we got object-oriented design patterns to begin with, so maybe this is a WordPress-centric variation of that.

Though I’ve written about things such as registries in previous articles (and ones that are not that old even), it’s never a bad idea to revisit the same topic especially when there’s something to continue to add to the previous take.

Continue reading

How To Downgrade Composer, PHP, and NPM

TL;DR: If you’re working on a variety of projects each of which requires different versions of PHP, Composer, and/or NPM you may need to change the version of all or any permutation of any of these utilities.

This article outlines what steps need to be taken to downgrade Composer, PHP, or NPM when working on any given project.

Continue reading

Writing PHP Command-Line Applications: Command-Line Arguments

TL;DR: $argv is an array of arguments passed to the script with the first index being the name of the script itself. And $argc is the number of arguments passed to the the script (which will always at least be 1).


Arguably, pun intended, one of the key pieces of command-line application is making sure that they are interactive through command-line arguments. In PHP, there are two variables to understand:

  • $argc is the number of arguments passed to script. Note the script’s filename is always passed as an argument to the script, therefore the minimum value of $argc is 1.
  • $argv is an array of arguments passed to script. Note the first argument $argv[0] is always the name that was used to run the script.
Continue reading

Writing PHP Command-Line Applications: A Basic Script

TL;DR: I’ve been writing PHP command-line scripts to help automate mundane tasks. As these tasks are growing in complexity or turning more into applications that interface with third-party APIs, I’m documenting the things I find important that others may also find helpful.


There are three things necessary to get a basic script up and running on your local machine (assuming you already have PHP installed):

  1. Know the path to the PHP binary,
  2. Make sure your script references said binary,
  3. And make the script executable.
Continue reading

Resolving PHP and PHP CodeSniffer Errors

macOS is still shipping with PHP (though how this looks for future versions of the OS is likely going to change in some way.).

Anyway, imagine you’re in a situation where you’re working on a project that requires three different components:

  1. PHP,
  2. A set of coding standards,
  3. PHP CodeSniffer that work with said coding standards,
  4. The inability to properly see results of sniffing the code either in your terminal or your IDE.

When this happens, this is almost always a result of a version of PHP, the version of the various dependencies, and making sure they all play well together.

In short, it’s about making sure the tools like PHP CodeSniffer work well with the same version of PHP you have installed. And in this case, the latest and greatest isn’t necessarily the best course of action.

It is, however, close. And in the following steps, you should be able to get everything working exactly as needed for your specific set up.

Continue reading
« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑