function buz() { echo __FUNCTION__, "\n"; } const FOO = 1; const BAR = 2; namespace Fiz\Biz\Buz; use function Foo\Bar\{fiz, biz, buz as boz, A}; use const Foo\Bar\{FOO as FOZ, BAR, B}; use Foo\Bar\{A, B, const BAR as BOZ}; function buz() { echo __FUNCTION__, "\n"; } const FOO = 100; echo "==== MIXED ====\n"; new A(); new B(); var_dump(BOZ); echo "===== CONSTANTS ====\n"; var_dump(FOO); var_dump(FOZ); var_dump(BAR); var_dump(defined('B')); echo "===== FUNCTIONS ====\n"; buz(); fiz(); biz(); boz(); A();
return 'foo'; }); expect(foo())->to->equal('foo'); }); it('allows the functions to accept parameters', function () { FuncFactory::create('bar', function ($foo, $bar) { return $foo . $bar; }); expect(bar('foo', 'bar'))->to->equal('foobar'); }); it('allows various parameter defaults', function () { FuncFactory::create('fiz', function ($a = 1, $b = 2.5, $c = [], $d = false, $e = null) { return [$a, $b, $c, $d, $e]; }); expect(fiz())->to->equal([1, 2.5, [], false, null]); }); it('overrides default parameters with only the passed ones', function () { FuncFactory::create('baz', function ($a = 1, $b = 2, $c = 3) { return [$a, $b, $c]; }); expect(baz('baz'))->to->equal(['baz', 2, 3]); }); it('benefits from the use keyword allowing variables in scope to be accessed', function () { $biz = 'biz'; FuncFactory::create('biz', function () use($biz) { return $biz; }); expect(biz())->to->equal('biz'); }); }); });