PHP code example of camspiers / closureaccess

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

    

camspiers / closureaccess example snippets



class A {
    use Camspiers\ClosureAccess;
    public function hello()
    {
        return "Hello";
    }
}

function run($fn) {
    return $fn();
}

$a = new A;

// an example of accessing a public method via properties and passing it around
echo run($a->hello), ', World';

// an example of executing a closure property as a method
$a->world = function () {
    return "World";
};

echo 'Hello, ', $a->world();