Skip to content

Commit

Permalink
feat: Adds parameter typehints to ContainerInterface
Browse files Browse the repository at this point in the history
This patch bumps the minimum supported PHP version to 7.2 and adds
parameter typehints to ContainerInterface, as the first step towards
adding explicit typehints based on the specification.

See https://www.php-fig.org/blog/2019/10/upgrading-psr-interfaces/
  • Loading branch information
weierophinney committed Jun 17, 2020
1 parent fc1bc36 commit 6c2bc7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=7.2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -21,7 +21,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "2.0.x-dev"
}
}
}
6 changes: 4 additions & 2 deletions src/ContainerInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Psr\Container;

/**
Expand All @@ -17,7 +19,7 @@ interface ContainerInterface
*
* @return mixed Entry.
*/
public function get($id);
public function get(string $id);

/**
* Returns true if the container can return an entry for the given identifier.
Expand All @@ -30,5 +32,5 @@ public function get($id);
*
* @return bool
*/
public function has($id);
public function has(string $id);
}

13 comments on commit 6c2bc7f

@XedinUnknown
Copy link

@XedinUnknown XedinUnknown commented on 6c2bc7f Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC-breaking change, as descendant signature must be identical, but it will not be because it would be missing the typehint, @weierophinney. Therefore, this should be in a new major version. Besides the fact that a previously supported PHP version was dropped.

@weierophinney
Copy link
Contributor Author

@weierophinney weierophinney commented on 6c2bc7f Mar 4, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XedinUnknown
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weierophinney, you are formally right. However, this is breaking stuff quite a bit. IMHO, if something that was supported is no longer supported, that's a BC break. But I understand the point, thanks.

@Jean85
Copy link
Member

@Jean85 Jean85 commented on 6c2bc7f Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XedinUnknown Composer protects you from upgrading to an incompatible version.
And this is a minor bump to leave space for patches on 1.0.x because 1.0 will stick around, it's not going away, and since it's a PSR we're absolutely not dropping support for a long time.

Also, as pointed out times and times again by Ocramius, bumping requirements is not a BC for SemVer: Ocramius/PackageVersions#105 (comment)
If something brakes on your side due to something like this, it's because you're doing something wrong, because you MUST run composer update only in production-compatible systems: Ocramius/PackageVersions#105 (comment)

@XedinUnknown
Copy link

@XedinUnknown XedinUnknown commented on 6c2bc7f Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am running composer update, and I depend on ^1.0. This means that I should not be getting breaking updates. But somehow I got breaking changes from dev-master, which is even stranger now that I see the alias changed to 2.0.x. 🤔

Just FYI: my problem is not with PHP versions; it is with signatures. In my project where I depend on ^1.0, as soon as I installed on PHP 7.2 I got the new signatures with typehints, and this broke the stuff. I'm trying to find the CI log for this, but no luck yet somehow...

@Jean85
Copy link
Member

@Jean85 Jean85 commented on 6c2bc7f Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that you're running with "minimum-stability": "dev".
You can't expect that nothing breaks if you do.

@XedinUnknown
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always thought that if I'm running with "minimum-stability": "dev", and depending on SemVer to not break BC (although I understand that SemVer's notion of BC relates only to the API and not dep constraints), then I should only get BC-breaking stuff it the break was unintentional.

@Jean85
Copy link
Member

@Jean85 Jean85 commented on 6c2bc7f Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On master it's 1.1.x-dev:

"dev-master": "1.1.x-dev"

That's why you got it, but it shouldn't break anything to you if you're on 7.2+. If you're not, you used --ignore-platform-reqs, which basically screws with all the safeguards of Composer.

@XedinUnknown
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I certainly do not use --ignore-platform-reqs. What is happening is that I have an interface that extends ContainerInterface, and when I implement it, the signatures are incompatible - even on PHP 7.4. I found the log, and you can see it here.

@jvasseur
Copy link

@jvasseur jvasseur commented on 6c2bc7f Mar 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a bit of time to try to find what was appending here and it looks like if you define an interface that has the same method than the ContainerInterface but without the type and then create an interface that extends both interface it doesn't work, even on PHP 7.4 : https://3v4l.org/INCMd

This looks like a bug in PHP since switching the interface order works without problems.

@XedinUnknown
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jvasseur, thank you very much, kind sir!

@XedinUnknown
Copy link

@XedinUnknown XedinUnknown commented on 6c2bc7f Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug reference: #67270, #76361, #80785. Gawd, I hate the PHP issue tracker, because it's impossible to just find what you need there. Spent a good 20 minutes trying different search terms.

There is an opinion that this is nevertheless not a bug, because it doesn't break any spec that says that inheritance order should be irrelevant. I don't care bug or not, and I recognize that we should know this behaviour and to work around it. It could be useful, however, if PHP had some info on this available - like somewhere here.

@XedinUnknown
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5fe95a7 (#28). Thanks a lot for your support!

Please sign in to comment.