improved/improved

This package is abandoned and no longer maintained. No replacement package was suggested.

Improved PHP library

Installs: 15 733

Dependents: 4

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Type:metapackage

v0.1.0 2019-06-03 17:01 UTC

This package is auto-updated.

Last update: 2020-06-28 10:54:28 UTC


README

improved PHP library

Playground for developing consistent and modern functions for PHP that are safe to use.

Most libraries here are in permanent beta, though some might become production ready. Any library written in PHP can be used, but is mostly intended as proof of concept.

If you choose to use these libraries, please provide feedback either through via github issues or via Twitter @ArnoldDaniels.

Why?

The core libraries of PHP are a mess. Functions have inconsistent names, inconsistent arguments, inconsistent and sometimes dangerouds return values and deal with errors poorly. This functions have been created decades ago and no longer live up to current day standards.

While there are many functions, a lot are redundant, while others are missing. For example;

  • There are many array functions, but these won't work with other iterables like ArrayObject.
  • For trimming a string there is trim, rtrim and ltrim. For padding a string there is only str_pad, which takes a STR_PAD_RIGHT, STR_PAD_LEFT or STR_PAD_BOTH as argument.
  • For missing functions there are standard patterns to make it work. For instance, to find out if a string contains a specific substring we use strpos($string, $substring) !== false.
  • etc

This make it unnecessarily difficult for non-PHP developers to read PHP code and creates a barrier for newcomers to an otherwise beginner-friendly language.

What?

All functions are consistently named and take the subject as first argument. The library reduces the number of functions, opting for the use of constants for options. Options are always the last argument.

The functions throw an Exception in case of an error and return only sensible data.

The library contains of the following packages:

  • iterable - Like array functions, for any iterable. Uses Generators.
  • functions - Function handling and functional programming.
  • type - Type checking and casting.

Roadmap

  • string - String manipulation.
  • array - Limited set of functions that don't make sense for other iterables.

For more high level functionality like database access, filesystem access, image processing, etc, it's recommended to use an OOP abstraction layer. This is outside of the scope of the improved PHP library.

How?

All modules code as extension or composer package. The extension is not yet available. The compatibility library can be installed via

composer install improved/improved

All functions are in the Improved namespace, rather than importing them one by one, it's recommended to alias the namespace to i.

use Improved as `i`;

if (i\type_is($value, '?string') {
    //...
}