PHP code example of jgswift / delegatr

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

    

jgswift / delegatr example snippets


$x = 10;
$y = 2;

$lambda = new delegatr\Lambda(function() {
    return $x + $y;
}, get_defined_vars());

var_dump($lambda()); // 12

class MyDelegate {
    use delegatr\Serializable;
}

$delegate = new MyDelegate(function() {
    return 'foo';
});

$serial_string = serialize($delegate);

$delegate2 = unserialize($serial_string)

var_dump($delegate2()); // returns 'foo';

$delegate = new delegatr\Lambda(function() {
    return 'foo';
});

class MyLambda extends delegatr\Lambda {
    /* ... */
}

class MyDelegate {
    use delegatr\Delegate;
}

$delegate = new MyDelegate(function() {
    return 'foo';
});

var_dump($delegate()); // returns 'foo';
sh
php composer.phar