- class_alias: documentation ( source)
- sprintf: documentation ( source)
<?php
namespace Foo
{
class Bar {
};
}
namespace {
use Foo\Bar;
class_alias(Bar::class, 'FooBar');
class GuineaPig {
public function withNamespace(Bar $bar)
{
echo sprintf("Passing %s worked with %s\n", get_class($bar), __METHOD__);
}
public function withoutNamespace(FooBar $bar)
{
echo sprintf("Passing %s worked with %s\n", get_class($bar), __METHOD__);
}
}
$bar = new Bar();
$foobar = new FooBar();
$pig = new GuineaPig();
$pig->withNamespace($bar);
$pig->withNamespace($foobar);
$pig->withoutNamespace($bar);
$pig->withoutNamespace($foobar);
}