Re: Type casting syntax
| From: | Mike Schinkel | Date: | Mon, 12 Jul 2021 20:36:53 +0000 |
| Subject: | Re: Type casting syntax | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115417@lists.php.net to get a copy of this message | ||
> On Jul 12, 2021, at 4:28 PM, Lynn <kjarli@gmail.com> wrote:
> On Mon, Jul 12, 2021 at 10:20 PM Mike Schinkel <mike@newclarity.net
> <mailto:mike@newclarity.net>> wrote:
> It seems you have just illustrated why in reality we really do not need type casting/assertions
> in PHP given its current features, because we already have what we need.
>
> That's not an argument I agree with, as it would invalidate the need for short closures,
> null coalesce, constructor property promotion, etc.
>
> Continuing on the previous example:
> ```php
> $service = $container->get(SomeService::class);
> assert($service instanceof SomeService);
>
> // could be replaced with
> $container->get<SomeService>();
In your hypothetical view here, what happens when the $container does not have SomeService to
provide? Does it throw an Exception?
-Mike