As a PHP programmer I’ve seen projects with a phpunit.xml file or a phpunit.xml.dist file (or even both, which is a mistake). These are configuration files for PHPUnit but why the two different file names? PHPUnit first tries to use phpunit.xml and if that file does not exist, then it tries to use phpunit.xml.dist instead. PHPUnit only uses one of these files, never both.
The behaviors of “require”, “include”, “require_once”, and “include_once” in PHP are all very similar with some slight differences. Here is the table highlighting the different behaviors of these statements.
What does declare(strict_types=1); do in PHP? PHP is a weakly typed language, which means that when a value is of the wrong type, PHP tries to cast it to the proper type. For example if you try to add an integer and a string, echo 5 + “3”; PHP will try to cast the string […]
By default phpcs does NOT display the relevant name of the sniff when a sniff fails. By adding the ‘-s’ argument, the sniff names will be displayed. See the following from ‘phpcs –help’. Alternatively, this can be added to your PHP CodeSniffer XML Ruleset.
When setting up a new site using PHPUnit 8.x and PHP 7.2, I got the error message: setUp() must be compatible with PHPUnit\Framework\TestCase::setUp Because we can now define the method as returning no value (with :void) and this is part of the method definition starting in PHPUnit 8.0.0, we need to add this in our […]
In PHP 5.5 the DateTimeImmutable class was introduced. Immutable objects are nice in that they can not be modified, which helps reduce the likelihood I make certain types of errors. This is how to ensure the DateTime you’re working with is immutable.
I’ve been using Local by Flywheel for my local WordPress development and I wanted to use Xdebug with Visual Code Studio with it. These are the notes I’ve made for myself in case I need to set this up again in the future.
When developing a WordPress theme, I often need to ensure I’m loading the latest version of the CSS file I’m working on. One way to do this is by appending a URL parameter (e.g. ?ver=123) that gets updated each time the file gets updated. Load Newest Assets Plugin Thanks to Corey Salzano for pointing out […]
There are a number of different inline conditionals I use when working with PHP (i.e. ternary conditionals and the null coalescing operator). As a reminder of how some of these common inline conditionals work, I put together this table for reference.