1. Go to this page and download the library: Download mpyw/unclosure 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/ */
mpyw / unclosure example snippets
use Mpyw\Unclosure\Value;
use PDO;
function withEmulation(PDO $pdo, bool $enabled): PDO
{
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $enabled);
return $pdo;
}
$connector = function (string $dsn) {
return new PDO($dsn);
};
// Eager Evaluation
$pdo = Value::withCallback($connector('sqlite::memory:'), 'withEmulation', true);
// Lazy Evaluation
$pdo = Value::withCallback($connector, 'withEmulation', true);
$pdo = $pdo('sqlite::memory:');
use Mpyw\Unclosure\Value;
use PDO;
function switchingEmulationTo(bool $enabled, &$pdo, callable $callback, ...$args)
{
return Value::withEffect(
$pdo,
function (PDO $pdo) use ($enabled) {
$original = $pdo->getAttribute(PDO::ATTR_EMULATE_PREPARES);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $enabled);
return function (PDO $pdo) use ($original) {
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $original);
};
},
$callback,
...$args
);
}
$connector = function (string $dsn) {
return new PDO($dsn);
};
// Eager Evaluation
$pdo = $connector('sqlite::memory:');
switchingEmulationTo(true, $pdo, function () use ($pdo) {
// Run queries that