> On 17 Nov 2021, at 00:22, André Hänsel <an...@webkr.de> wrote:
> 
> It is common (with DI systems for example) and to my knowledge not
> particularly discouraged to have function parameters that are supposed to
> accept something like Foo::class, which currently is a string.
> 
> It seems logical to ask for a special type that can hold class names, so
> that parameters that can accept a class name can be type hinted more
> specifically than just (any) "string".
> 
> Regardless of whether or not such a proposal would be accepted or declined
> (for complexity reasons maybe) I couldn't even find any such proposal. Has
> this really never been asked?
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
> 
Hi André,

I’ve wondered about this kind of functionality myself, but IMO to be 
particularly useful it’d need to support the ability to accept a classname that 
is a subtype of a parent class or interface. I can’t think of too many places 
where I’d want to know something is a classname reference, and not also want to 
know that it's a subclass or implementation of something specific.


This typeof functionality could support some very expressive solutions, when 
combined with union types, and anonymous classes. 




Cheers

Stephen 
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to