https://github.com/sof3/static-overloads
Use parameter-varying method overloads in PHP
https://github.com/sof3/static-overloads
method-overloading overload
Last synced: 2 months ago
JSON representation
Use parameter-varying method overloads in PHP
- Host: GitHub
- URL: https://github.com/sof3/static-overloads
- Owner: SOF3
- License: apache-2.0
- Created: 2017-12-30T18:02:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-31T12:47:39.000Z (over 7 years ago)
- Last Synced: 2025-01-25T10:41:17.385Z (4 months ago)
- Topics: method-overloading, overload
- Language: PHP
- Homepage: https://packagist.org/packages/sof3/static-overloads
- Size: 16.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# static-overloads
Use parameter-varying method overloads in PHPPass 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.
Example:
```php
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);
}
]);
```