# Tagged

PHP

18 articles

Results18 found
Nov 2, 2018
PHP

FizzBuzz in PHP: A Fresh Approach

FizzBuzz is a very popular programming question that tests your logic to see if you can build a simple program.

1 min read
Nov 1, 2018
PHP

PHP's array_reduce is not only for outputting single values

PHP's array_reduce is a simple way to partition a set of data or return a single value. It is super powerful and worth spending time learning.

2 min read
Nov 16, 2016
PHP

Support for keys in list(), or its new shorthand syntax [] in PHP

Now as of PHP 7.1, you can define the keys of your array that will be parsed when destructuring your arrays. Prior to PHP 7.1, you could only use arrays with numeric indexes. Now with this new addition, our lives just got easier.

1 min read
Nov 15, 2016
PHP

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.

1 min read
Nov 14, 2016
PHP

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.

1 min read
Nov 13, 2016
PHP

Setting Visibility for Your Class Constants 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.

1 min read
Nov 12, 2016
PHP

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.

1 min read
Nov 11, 2016
PHP

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.

1 min read
Nov 10, 2016
PHP

Using PHP's array_map to format your arrays without loops

So let's face it, loops are a bit boring. So how can we mix it up? Let's assume we have a case where we have a CSV file that we want to quickly parse.

2 min read
Nov 9, 2016
PHP

SOLID Principles in PHP

The 5 basic principles for Object-Oriented Design, SOLID, were first created in an 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.

7 min read
Nov 8, 2016
PHP

Filtering Arrays Without Using Loops in PHP

PHP has a built-in function called array_filter that allows you to filter through your arrays without the need for a loop. Personally, this approach feels much cleaner to me and simpler to comprehend.

1 min read
Nov 7, 2016
PHP

Void Return Types in PHP

As of PHP 7.1, we can now use void return types within our methods. This is useful for cases where you have methods that are just setting or processing data without the need of returning any values.

1 min read
Nov 6, 2016
PHP

Type Hinting with Nullable Types in PHP

As of PHP 7.1, you can now set your type declarations as nullable by simply prefixing them with a question mark ?. In doing so a null value can be passed in as a parameter or returned as a value for your methods.

1 min read
Nov 5, 2016
PHP

PHP Group Multiple use Declarations

As of PHP 7, you can now group your imported classes, functions, and constants from under the same namespace.

1 min read
Nov 4, 2016
PHP

PHP Null Coalescing Operator

One of my new favorite additions to PHP 7, is the Null Coalescing Operator. It cleans up your code by removing a tedious step of checking if some value is isset() and not NULL and returning it or if not setting a default.

1 min read
Nov 3, 2016
PHP

PHP Spaceship Operator

One of the new features to hit PHP 7 is the Spaceship Operator. This new trick helps improve the way you'd compare 2 expressions. In short, the comparison returns 1 of 3 values (-1, 0, or 1) depending on the result of the comparison.

2 min read
Nov 2, 2016
PHP

Return Type Declarations in PHP

PHP 7 now makes it possible to declare return types for your methods. This allows you better control over the data that will be returned from each method in your application.

3 min read
Nov 1, 2016
PHP

Scalar Type Hints in PHP

Starting with PHP 7.0, it's now possible to declare scalar type hints for your method arguments. Previously, we were able to use array and callable, but now with PHP 7+, we have much more control.

1 min read