Per the discussions started earlier this year, I've opened two pull
requests to "evolve" the PSR-11 ContainerInterface to use explicit type
hints:

The first — https://github.com/php-fig/container/pull/27 — updates the
psr/container package to require PHP 7.2, and adds the `string` typehint to
the `$id` parameters of each of the `has()` and `get()` methods. The
intention is for this to be tagged as v2.0, and would allow implementations:

- Immediate forwards compatibility, as the covariance/contravariance rules
of PHP 7.2 allow implementations to accept wider type ranges for parameters.
- The ability to make themselves forwards compatible with a later release
by adding return type hints, as this is be covered by the same
covariance/contravariance rules (implementations can return a narrower set
of types than their parent types).

The second — https://github.com/php-fig/container/pull/28 — builds on the
previous, and updates the psr/container package to add a return type of
`bool` to the `ContainerInterface::has()` method. The intention is for this
to be tagged as v3.0.

These changes follow the specification verbatim, as the `$id` arguments are
documented as strings. Further, I do not think this is a place where the
proposed `Stringable` interface for PHP 8 comes into play; the context when
pulling from a service container is generally to provide either a class
name or a string service name; using a class to represent that is a
sufficiently edge case that I see no good argument to wait for PHP 8 so we
can do `string|Stringable` in this particular specification.

Finally, I have not proposed a return typehint for `get()`, as the
specification as written explicitly allows `mixed`. Not having a return
type is the technically correct approach in this context.

If there are no objections, I'd like to get these moved forward.

Thanks!

-- 
Matthew Weier O'Phinney
mweierophin...@gmail.com
https://mwop.net/
he/him

-- 
You received this message because you are subscribed to the Google Groups "PHP 
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to php-fig+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/CAJp_myXXuHj2YOicMVV6W_U_4vacrc1UBLQXsvLTzLA1i3AH3w%40mail.gmail.com.

Reply via email to