Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matin Hujer:
Consistence brings consistency to the PHP
Feb 06, 2018 @ 16:50:05

On his site today Matin Hujer has posted a tutorial covering the use of the Consistence library, a package that is designed to provide a consistent interface to PHP's functionality.

There is no argument, that PHP can sometimes be a bit inconsistent about naming stuff and maintaining order of parameters for related functions. Also, in some cases it is not strict and allows you to use the language and the functions in a wrong way. Sometimes you get false as a return value where an exception would be appropriate.

[...] Consistence provides opinionated strict wrappers with better error handling and consistent naming and consistent parameters order.

The remainder of the post goes through some of the functionality the package provides including:

  • Enums for better type safety
  • [Using] ObjectPrototype to disable magic methods
  • Consistent array manipulation functions
  • [Working with] Regular expressions

As a related piece he's also created PHPStan static analysis rules for the library to ensure it's being used correctly.

tagged: language consistency package library tutorial

Link: https://blog.martinhujer.cz/consistence-brings-consistency-to-the-php/


Trending Topics: