PHP code example of daveross / phpoverloading

1. Go to this page and download the library: Download daveross/phpoverloading 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/ */

    

daveross / phpoverloading example snippets




class A {}
class B extends A{};

class Foo {
    function __construct_a() {
        ...
    }
}

class Example {

    use \DaveRoss\PHPOverloading\OverloadedMethods;

    public $string, $integer;

    public function __construct_string($val) {
        $this->string = $val;
    }

    public function __construct_integer($val) {
        $this->integer = $val;
    }

}

$strExample = new Example("hello world");
$intExample = new Example(5);

class Example {

    use \DaveRoss\PHPOverloading\OverloadedMethods;

    public $string, $integer;

    public function example_string($val) {
        echo 'the string is ' . $val;
    }

    public function example_integer($val) {
        echo 'the integer is ' . $val;
    }

}

$x = new Example();
$x->example("hello world"); // echoes "the string is hello world"
$x->example(5); // echoes "the integer is 5"
example_array
__construct_default