-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The exception is not implementing Throwable #33
Comments
@Nyholm thanks for opening this discussion. We already discussed this internally, and extending As you pointed out, dropping the Hence, we had to rush the patch on both major releases, so that no one could install something that could break their code not to their fault; we could've said "your problem, you just need to change the To be fair, the concrete classes that implement those interfaces must implement I hope you'll find this answer sufficient. |
Yes, @Nyholm if the previous discussions you will find that:
That way projects on 8.0 will get the last release (with good static analysis), the rest will have 1.1.1/2.0.1 installed.
The pull request for 1.1/2.0 was opened for years, but that didn't allow us to catch the PHP 7.4 bug. What was done in 1.1.1 and 2.0.1 were emergency lifesavers, waiting a year for review on that wasn't possible. What consequences do you have in mind exactly related to those pull requests?
2.1 should, not sure if we decided whether 1.2 was worth it 🤔 |
I understand that it was an unexpected issue. I don't think it is weird that we made a mistake here. It is the way the mistakes were fixed that I'm more hesitant about. I opened this issue to make sure this package is the best it can be. Im happy there is a plan to drop PHP <7.4 in the next minor release and that we add back |
Exactly. It's in the spirit of our bylaw to smooth the upgrade path as much as possible, so doing in the 1.x branch is good 👍 PS: for adding |
Maybe totally out of scope of this, but why do error types need to be interfaces? A Grateful if someone can point if am missing something about why people use interfaces for this. In my opinion, FIG should consider moving away from error types as interfaces in future majors. |
@mnavarrocarter Purpose of this package is to provide interfaces that containers could implement thus guaranteeing that if the user only uses methods and classes provided by this package the actual container implementation can be any as long as it follows the contract established by this package. If, as you suggested, a |
Hi @martinssipenko , thanks for taking the time to answer. I think this will explain my point better. If you have: <?php
class ContainerException extends Exception
{
}
class NotFoundException extends ContainerException
{
} You can then do: <?php
try {
$container->get('some-service');
} catch (ContainerException $e) {
// Handle this general container error
}
try {
$container->get('some-service');
} catch (NotFoundException $e) {
// Handle this more specific error, which means a service was not found
}
// You can even catch and handle both differently
try {
$container->get('some-service');
} catch (NotFoundException $e) {
} catch (ContainerException $e) {
} This is absolutely possible and reasonable. In fact, is idiomatic PHP, as the standard library exceptions (Runtime, InvalidArgument, etc) all extend the base |
The user code needs to be implementation independent. And this psr package should only include interfaces. Im happy with the initial responses. Im closing this issue because it is way off topic. |
This is still possible with interfaces though, and on the contrary, since we don't have multiple inheritance on classes, you'll be binding the end user to expand With an interface, you can still extend your custom exceptions AND follow the spec. This is pretty important for interoperability, where preexisting implementations could have their exception hierarchy, and we can't ask them to break BC because of this. |
Dependency Inversion. We build inside-out. Our PSR packages aren't implementations, they're contracts. Hope that answers your question @mnavarrocarter ? |
I would argue that in practice, implementors end up doing that. And also argue that there is no problem with extending
There are others fig packages that contain implementation logic, like
I get that. The main interface here is well designed and extremely useful. This is not the case with the error ones. The only possible implementation of an interface that serves as error marker is |
Let's say you have your own exception classes, but they already extends other exceptions, and they do not have a common ancestor (except at the root with
Now you want to support/implement PSR-11. With an exception class, you can't; with an interface, you can. |
That's is easily solvable by rolling a new major of your library that adds support for the PSR. It is very likely you have to modify your |
@mnavarrocarter this could have been an option years ago. And I do see your point, it makes sense. Now the reality is that it's no longer an option, we can't break something that big. |
Totally understand that @mnapoli . I maintain some packages myself. That's what I said that maybe it should be considered if there is ever a next major for some reason. I agree with you that this issue only is not worth enough to tag a 3.x. Just being opened to the possibility was really the goal. |
IMHO, forcing adopters to do a BC with a major version bump should not be the preferred way to go. Ensuring a smooth-as-possible adoption path was always the key to success of many major PHP-FIG PSRs, and choosing a different path was always done with a careful consideration beforehand, because it's a hard trade-off. |
We'll leave it here as this issue is quite long already. I think I've made my point clear anyways. |
Here is the history:
Version 1.0.0
The extension interface did not extend
\Throwable
Version 1.1.0
The extension interface did extend
\Throwable
Version 1.1.1
The extension interface did not extend
\Throwable
.Version 2.0.0
The extension interface did extend
\Throwable
as it should since it is a new major release and we don't need to consider edge cases with the BC layer.Version 2.0.1
The extension interface does not extend
\Throwable
.Except for adding 3 type hints, these are the only changes in this repository. How can I, as an open source maintainer, reliably depend on this package? Or how can I, as a user that like static analyses, know what exception to catch? Catching
NotFoundExceptionInterface
orContainerExceptionInterface
is technically not valid.I understand that there was things nobody could expect when releasing 1.1.0. But in my opinion it was a misstake releasing 1.1.1 and 2.0.1. It is way better being predictable and slightly wrong.
Im not seeking to put blame nor do I require an explanation
I just want us to be aware of this and focus on 2 things moving forward:
\Throwable
The text was updated successfully, but these errors were encountered: