2017 © Pedro Peláez
 

package null-object

A Null Object for PHP.

image

conceptbyte/null-object

A Null Object for PHP.

  • Monday, July 25, 2016
  • by rajdeeptarat
  • Repository
  • 2 Watchers
  • 5 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

Null Object for PHP

Allows the user to call the null object which handles all calls silently and returns sensible defaults. The returned object can be type cast to return the following values:, (*1)

  • String - ""
  • Integer - 0
  • Float or Real - 0.0
  • Array - []
  • Boolean - False

Installation

Run the following to install:, (*2)

composer require conceptbyte/null-object, (*3)

Usage

The null object can be created in one of the following methods: - Named constructor: NullObject::create() - Helper function: no(), (*4)

Both will return an instance of the class. Calls to any methods or members on this class will return the defaults as mentioned in the section above., (*5)

Example

(string) NullObject::create()->xyz; // ""
(bool) NullObject::create()->abc(); // false
(int) no()->xyz; // 0
(float) no()->abc(); // 0.0

Quirks

PHP does not allow modifying the behaviour of casting a class to boolean. A simple hack is to use the SimpleXMLElement class which can return false when passed an empty XML tag., (*6)

The Versions

25/07 2016

dev-master

9999999-dev

A Null Object for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

null null-object null-object-pattern

25/07 2016

v1.0.0

1.0.0.0

A Null Object for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

null null-object null-object-pattern