RE: [PHP-DEV] Is there an RFC/discussion for ::class being a specific type?
| From: | André Hänsel | Date: | Tue, 16 Nov 2021 18:30:56 +0000 |
| Subject: | RE: [PHP-DEV] Is there an RFC/discussion for ::class being a specific type? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116422@lists.php.net to get a copy of this message | ||
Maybe I'm missing something but now that you said it's kind of a macro, I think it would
actually be pretty easy to implement, at least when not taking backwards compatibility or
performance into account:
class ClassName {
private $name;
function __construct(string $name) {
$this->name = $name;
}
function__toString()
{
return $name;
}
}
Then make the preprocessor convert Foo::class into
new ClassName(Foo::class). Done. Now
you can type hint a function like this:
class DiContainer {
function get(ClassName $klass) {
// ...
}
}