2017 © Pedro Peláez
 

library static-overloads

Use parameter-varying method overloads in PHP

image

sof3/static-overloads

Use parameter-varying method overloads in PHP

  • Sunday, December 31, 2017
  • by SOFe
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

static-overloads

Use parameter-varying method overloads in PHP, (*1)

Pass an array of functions with different signatures into the Overload constructor. Invoke the Overload object directly with an array of the parameters you got, and the library will determine the correct implementation to use based on the parameter types., (*2)

Example:, (*3)

function my_func(...$args){
    // We are storing the Overload object as a static-scope variable.
    // This caches the analyzed implementation signatures to improve runtime performance
    // if the function is called frequently within the same runtime.
    static $overload = null; // due to PHP language limitations, $overload cannot be initialized inline.
    $overload = $overload ?? new Overload([
        function(string $a){
            implementation1($a);
        },
        function(int $a){
            implementation2($a);
        }
    ]);

The Versions

31/12 2017

dev-master

9999999-dev

Use parameter-varying method overloads in PHP

  Sources   Download

Apache-2.0

The Requires

  • php ^7.0
  • ext-reflection ^7.1

 

The Development Requires

by Avatar SOFe