Download the PHP package 1tomany/nullify without Composer

On this page you can find all versions of the php package 1tomany/nullify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package nullify

String Nullifier for PHP

This simple library exposes a single function named nullify() in the global namespace. By default, the function trims the string passed into it and returns null if the trimmed value is an empty string, or the trimmed string otherwise.

Installation

Usage

The nullify() function has the following signature:

If the $trim argument is set to false, the string is not trimmed. An empty string will still return null, otherwise, the original string is returned. If an object implementing \Stringable is passed in, the object will be converted to a string first.

Purpose

Dealing with falsy and empty values in PHP has always been a challenge. If you've used the language long enough, you've probably been bitten by empty('0') returning true even though the string '0' clearly isn't empty. My preference is to typehint strings as non-empty-string|null to clearly indicate what kinds of values that variable holds.

Take the following basic DTO as an example:

Because of the ambiguity of the $name property, it's cumbersome to determine if it is empty or not:

For all practical purposes, $name is empty, but determining that is cumbersome.

A much clearer DTO would be written like this:

It's immediately clear what data $name holds, and testing if $name is empty or not is a cinch:

These are also clear because nullify() has removed any ambiguity around falsy or empty values:

Examples

$string $trim nullify()
null true null
'' true null
'' false null
' ' true null
' ' false ' '
'0' true '0'
'0' false '0'
' 0 ' true '0'
' 0 ' false ' 0 '
' PHP ' true 'PHP'
' PHP ' false ' PHP '
' 🐘🎉 ' true '🐘🎉'

Credits

License

The MIT License


All versions of nullify with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
ext-mbstring Version *
symfony/string Version ^7.4|^8.0|^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package 1tomany/nullify contains the following files

Loading the files please wait ...