echo "ReflectionFunction(1):"; var_dump($rf->getStaticVariables()); foo(); echo "ReflectionFunction(2):"; var_dump($rf->getStaticVariables()); foo(); $rf = new ReflectionFunction('foo'); echo "ReflectionFunction(3):"; var_dump($rf->getStaticVariables()); echo "---- ReflectionMethod ----\n"; $rf = new ReflectionMethod('Bar', 'foo'); echo "ReflectionMethod(1):"; var_dump($rf->getStaticVariables()); Bar::foo(); echo "ReflectionMethod(2):"; var_dump($rf->getStaticVariables()); Bar::foo(); $rf = new ReflectionFunction('foo'); echo "ReflectionMethod(3):"; var_dump($rf->getStaticVariables()); echo "---- ReflectionClosure ----\n"; $rf = new ReflectionFunction($foo); echo "ReflectionFunction(1-closure):"; var_dump($rf->getStaticVariables()); $foo(); echo "ReflectionFunction(2-closure):"; var_dump($rf->getStaticVariables()); $foo(); $rf = new ReflectionFunction($foo); echo "ReflectionFunction(3-closure):"; var_dump($rf->getStaticVariables());
<?php trait T { public final function foo() { return 'T::foo'; } } class Foo { use T; } class Bar extends Foo { public final function foo() { return 'Bar::foo'; } } $bar = new Bar(); echo $bar->foo() . "\n";
<?php namespace jubianchi; use jubianchi\Traits\Foo; require_once __DIR__ . '/Traits/Foo.php'; class Bar { use Foo; } xdebug_start_code_coverage(); $b = new Bar(); $b->foo(); var_dump(xdebug_get_code_coverage()); $reflector = new \ReflectionClass('\\jubianchi\\Bar'); var_dump($reflector->getMethod('foo')->getFileName(), $reflector->getMethod('foo')->getStartLine(), $reflector->getMethod('foo')->getEndLine());
function test_references() { // basic references (belongs_to) $f = new Foo(array('id' => 1, 'name' => 'Joe')); $f->put(); $b = new Bar(array('id' => 1, 'name' => 'Jim', 'foo' => 1)); $b->put(); $this->assertEquals($b->name, 'Jim'); $this->assertEquals($b->foo, 1); $this->assertEquals($b->foo()->name, 'Joe'); $this->assertEquals($b->foo()->name, 'Joe'); // fake reference should fail try { $this->assertTrue($b->fake()); } catch (Exception $e) { $this->assertRegExp('/Call to undefined method Bar::fake in .+tests\\/ModelTest\\.php on line [0-9]+/', $e->getMessage()); } }
<?php namespace Dotink\Lab; use Dotink\Parody\Mime; return ['setup' => function ($data, $shared) { needs('src/Quip.php'); needs('src/Mime.php'); }, 'tests' => ['Test' => function ($data, $shared) { $static = Mime::define('Bar'); $instance = Mime::create('Bar')->onCall('foo')->give('bar'); $static->onCall('foo')->give('bar'); assert(\Bar::foo())->equals('bar'); assert($instance()->foo())->equals('bar'); $instance = $static->create()->onCall('foo')->give('bar'); assert($instance()->foo())->equals('bar'); $static->onNew('test', function ($mime) { $mime->onCall('foo')->give('foo'); }); $instance = new \Bar('test'); assert($instance->foo())->equals('foo'); }]];