<?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);
}
Passing Foo\Bar worked with GuineaPig::withNamespace
Passing Foo\Bar worked with GuineaPig::withNamespace
Passing Foo\Bar worked with GuineaPig::withoutNamespace
Passing Foo\Bar worked with GuineaPig::withoutNamespace
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Passing Foo\Bar worked with GuineaPig::withNamespace
Passing Foo\Bar worked with GuineaPig::withNamespace
Passing Foo\Bar worked with GuineaPig::withoutNamespace
Passing Foo\Bar worked with GuineaPig::withoutNamespace
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /in/s1AlG on line 13
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in /in/s1AlG on line 13
Process exited with code 255.