Type Hinting With The Iterable pseudo-type In PHP

As of PHP 7.1, you can now type hint your method/function arguments with the keyword iterable for handling arrays or even objects that implement the Traversable interface. Let’s create an example where we can convert any string to a slug. We’ll have 2 methods so that we can pass either a string or iterable data. […]

Read More »

Type Hinting Callable Functions in PHP

As of PHP 5.4, you can type hint your method arguments with the callable keyword allowing you to enforce the type of data that is passed via your arguments . Let’s look at an example where we create a Sort class, with a custom method that takes a callable function so that we can customize […]

Read More »

Setting Visibility For Your Class Constant’s In PHP

Now in PHP 7.1+, you can set different visibility modifiers for each of your class constants. The available visibility modifiers consist of public, protected, and private. Any constant’s within your class set to protected or private that you try to access directly outside of the class will throw a Fatal Error. Example Usage <?php class […]

Read More »

Using Anonymous Classes in PHP

As of PHP 7, you can now create quick throwaway objects for use within your projects. This can be especially useful for your automated tests, for instance, with allowing you to create quick implementations of your interfaces. Let’s review a Notifier interface that we may have. We can easily create a anonymous implementation by using […]

Read More »

Symmetric Array Destructuring in PHP

As of PHP 7.1, you can now use the shorthand array syntax to destructure your arrays for assignment. Previously you would have had to use a function like list, but now you can use the simple new array shorthand syntax. Let’s look at some examples. Basic Example <?php $names = [ 'Frank Perez', 'Carmella Osman', […]

Read More »

SOLID Principles in PHP

The 5 basic principles for Object Oriented Design, SOLID, were first created in a effort to improve maintainability in our code bases. SOLID is a mnemonic acronym that stands for each of the following principles: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion. In this article, I’ll explain in short what each principle […]

Read More »

Filtering Arrays Without Using Loops in PHP

Have you ever had the need to filter through an existing array and create a new array based on your filter for your application to process? I’m sure the majority of you have, and personally I find it a bit tedious having to create a loop each time I need to filter through the data […]

Read More »