> The type widening RFC makes it easier to move to parameter types for
existing libraries.

I'm curious to see how you'll set the version constraint in your
composer.json file.

After adding a scalar type-hint to an interface, which is a breaking change
in 7.0 and 7.1, but a non-breaking change in 7.2, is the new version of
your package a major or minor release?

If you release it as minor, you'll need a PHP version constraint like
"^5.5, ^7.2", but excluding 7.0-7.1 In that way is itself a breaking
change, so likely your only practical move is to release (and commit to
maintain!) both major and minor versions, which doesn't sound easy at all.


On May 29, 2017 00:53, "Dan Ackroyd" <dan...@basereality.com> wrote:

> On 28 May 2017 at 14:25, Rasmus Schultz <ras...@mindplay.dk> wrote:
> >
> > To me, that's a setback that leads to harder-to-debug errors, and
> increases
> > learning-curve.
>
> Everything is a trade-off. The type widening RFC makes it easier to
> move to parameter types for existing libraries.
>
> While I can see what you mean about how it could lead to more
> accidental errors, for me at least, it would be actually quite hard to
> not notice those errors in the code.
>
> First, when people are programming against the interface rather than
> the implementation, that type of mistake is much easier to spot.
>
> function foo(Repository $repo) {
>     $repo->save(new stdClass());
>     // The above line is marked as an error in any decent IDE
>     // or code analysis tool.
> }
>
> Second, accidentally dropping the type from the parameter is also an
> easy mistake to spot.
>
> class UserRepository implements Repository {
>     public function save($item) {
>         // When inside this function the programmer has no idea
>         // what type item is. Any call to a method or property will
>         // be marked as a potential error either by an IDE, static
>         // analysis tool, or just the programmer realising
>         // "that parameter has no type".
>     }
> }
>
> So, to me (and possibly others who voted for the RFC) the ability to
> add types to interfaces without breaking implementing library is a
> good trade-off.
>
> And yes, the type system in PHP could definitely be improved. Perhaps
> you could propose an RFC? I suspect it might need to target PHP 8. I'm
> personally hoping that some form of the union type RFC could return,
> though possibly in a more general form.
>
> cheers
> Dan
> Ack
>

Reply via email to