Exemplo n.º 1
0
--FILE--
<?php 
use php\lang\Environment;
use php\util\Shared;
ob_implicit_flush(1);
Shared::resetAll();
$env1 = new Environment();
$env2 = new Environment();
function foobar($value)
{
    return Shared::value('foobar', function () use($value) {
        return $value;
    });
}
$env1->importFunction('foobar');
$env2->importFunction('foobar');
$env1->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('x')->get());
});
$env2->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('y')->get());
});
var_dump(Shared::reset('foobar'));
$env2->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('y')->get());
});
?>
--EXPECTF--
Exemplo n.º 2
0
use php\lang\Environment;
class Foo
{
}
function bar()
{
}
$env = new Environment();
$env->execute(function () {
    ob_implicit_flush(true);
    var_dump('class Foo exits: ', class_exists('Foo'));
    var_dump('function bar exits: ', function_exists('bar'));
});
echo "\nImport ...", "\n";
$env->importClass('Foo');
$env->importFunction('bar');
$env->execute(function () {
    ob_implicit_flush(true);
    var_dump('class Foo exits: ', class_exists('Foo'));
    var_dump('function bar exits: ', function_exists('bar'));
});
?>
--EXPECT--
string(17) "class Foo exits: "
bool(false)
string(20) "function bar exits: "
bool(false)

Import ...
string(17) "class Foo exits: "
bool(true)