PHP code example of shindakioku / overload

1. Go to this page and download the library: Download shindakioku/overload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shindakioku / overload example snippets


class Bar {}

class Foo
{
    public function withoutArguments(): string
    {
        return 'string';
    }

    public function argument1(string $name): string
    {
        return $name;
    }

    public function argument2(int $number): int
    {
        return $number;
    }

    public function withObject(Bar $bar): Bar
    {
        return $bar;
    }
}

$overload = new Overload\Overload(
    new Overload\OverloadClass(Foo::class), 'argument1', 'argument2'
);

$overload->call('shinda'); // argument1
$overload->call(2); // argument2

$bar = (new Overload\Overload(
    new Overload\OverloadClass(Foo::class), 'withObject'
))->call(new Bar); // $bar = Bar object;

(new Overload\Overload(
        new Overload\OverloadClass(Foo::class), 'withoutArguments'
    ))->call(); // 'string'