• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Archives for PHP

PHP

trailingslashit() vs untrailingslashit()

Last updated on November 1, 2022 by Sal Ferrarello

WordPress has two functions that can be helpful when dealing with the final character of a URL, trailingslashit() and untrailingslashit(). I find it preferable to use untrailingslashit() for two reasons: 1. It does not break empty checks and 2. It makes my sprintf() statements more readable.

Filed Under: Computing, Dev Tips, Programming Tagged With: PHP, WordPress, WordPress Plugin

WordPress Hooks and PHP Namespaces

Last updated on July 22, 2021 by Sal Ferrarello

While PHP namespaces allow you to refer to a function in file without using the fully qualified name, there is a catch when adding a WordPress hook or filter. The PHP __NAMESPACE__ magic constant can be helpful in this situation.

Filed Under: Dev Tips, Programming, Recommendations Tagged With: PHP, WordPress, WordPress Filter

phpunit.xml vs phpunit.xml.dist

Last updated on April 20, 2021 by Sal Ferrarello

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.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming, Recommendations Tagged With: PHP, PHPUnit

PHP require vs include

Last updated on January 28, 2022 by Sal Ferrarello

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.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming Tagged With: PHP

PHP declare(strict_types=1);

Last updated on October 23, 2019 by Sal Ferrarello

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 […]

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Computing, Draft, Programming Tagged With: PHP

phpcs display sniff name

Last updated on October 20, 2022 by Sal Ferrarello

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.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming, Solution Tagged With: PHP, PHPCS

setUp() must be compatible with PHPUnit\Framework\TestCase::setUp

Last updated on August 26, 2019 by Sal Ferrarello

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 […]

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming, Solution Tagged With: PHP, PHPUnit

PHP Convert to DateTimeImmutable

Last updated on February 25, 2019 by Sal Ferrarello

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.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Draft, Programming Tagged With: DateTime, PHP

Xdebug in Visual Code Studio with Local by Flywheel

Last updated on September 18, 2018 by Sal Ferrarello

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.

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming, Solution Tagged With: Local by Flywheel, PHP, Visual Code Studio, Xdebug

Load Newest CSS in WordPress

Last updated on August 2, 2018 by Sal Ferrarello

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 […]

Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Solution Tagged With: PHP, WordPress Theme

  • Go to page 1
  • Go to page 2
  • Next Page»

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in