PHP code example of peridot-php / peridot-scope

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

    

peridot-php / peridot-scope example snippets


$scope = new Scope();
$scope->name = "Brian";

$fnWithName = function() {
    print $this->name;
};

$fnWithName = $scope->peridotBindTo($fnWithName);

$fnWithName(); //prints "Brian"

class Test
{
    use ScopeTrait;
    
    protected $definition;
    
    public function __construct(callable $definition)
    {
        $this->definition = $definition; 
    }
    
    /**
     * Return the definition bound to a scope
     */
    public function getDefinition()
    {
        $scope = $this->getScope();
        return $scope->peridotBindTo($this->definition);
    }
}

$ composer