-
Notifications
You must be signed in to change notification settings - Fork 824
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
ENH Various fixes for PHP 8.1 compatibility #10281
ENH Various fixes for PHP 8.1 compatibility #10281
Conversation
I gather the thinking here is just that we're swapping out the raw php exception to one more in line with the exceptions that are likely already being caught elsewhere in our code? This feels like something that at least needs a brief mention in changelogs, since we're now throwing an exception where previously we did not (developers would either just get a warning, or get a Also how does this react with things like pstgres or pdo? I note the below:
Does this mean there's been an exception thrown by PDO in php 8.0 this whole time? Is it the same exception we're catching here, or a different one? |
Yes
I don't know. This particular issue surfaced when doing I don't think we shouldn't let postgres/pdo block this just yet, though I've created a new issue to investigate to see if further work needs to be done. |
Sweet. Given that pdo and postgres are slightly separate and there's an issue created to investigate that, I'm happy to move forward with this approach. I think it's good, would you mind just adding a quick sentence on the changelogs so people know they might need to start catching this exception in places they previously didn't need to? |
93ebd7b
to
3f062a1
Compare
I've updated the code so that it calls I don't think this change really needs a changelog update. MySQL explicitly throwing errors in PHP 8.1 is independent of Silverstripe. I think it's correct to NOT "backport" this behaviour to Silverstripe running older versions of PHP. |
Except that we're making changes in Silverstripe to account for the new thrown exception. After taking a closer look I think I agree that it doesn't need to be added to the changelogs - but I also wonder if we should just be setting |
7dad949
to
7a88f91
Compare
Have updated to set |
@silverstripe/core-team can we get a third opinion on this please? I think this is fine but it is a (very low risk) breaking change. I think if we just pop a sentence in the changelog like "as of php 8.1, failed mysql statements throw an |
I tried to read the convo but not sure I fully get what the options here are. Is it
If we're trying to be as PHP 8.1 as possible, I'd say do 1, and add a short mention to changelog. |
When we call prepare statement internally, are we then catching these errors and handling them as we would normally, or would we see application layer database calls or those made through the ORM throwing too with this change? I think if it only throws for people calling I'd also make the argument that if the only time these would now be thrown is direct use of the method because our internal code is just catching them all anyway, then what's the point in throwing it at all if we implicitly silence it everywhere anyway? So, my vote would be to err on the side of keeping the current behaviour and just swallowing the error as we currently do. |
Keep in mind that upgrading to PHP 8.1 isn't the only way to get the |
Oh right, I see. Not so straightforward, then! Given this is an explicit change in behaviour in php and not explicit change in our implementation, I think I'd be happy with either approach, but I'd still probably lean slightly towards swallowing the exceptions (it feels like the framework's job to put one try/catch in rather than expecting developers to litter their code with it) and we are then taking active steps to try to maintain some consistent behaviour across PHP versions (again, arguably one of the jobs of a framework). |
Just trying to wrap my head around this. I take it no one is arguing that there's a legitimate use case where properly written code will call Given the above assumption, I don't think we would be breaking anything that's no already broken by throwing an Exception. So we're mostly arguing about developer experience. My instinct in those situation would be to let Exception bubble up so devs can become aware of the problem. I suspect that's probably why PHP decide to start throwing an Exception in this situation. My instinct would be merge this. If we're concerned that this will break someone's code somehow, maybe do nothing and point the figure at PHP8.1 when they start complaining. Swallowing the exception wouldn't be terrible, but that's my least preferred option. It's worth pointing out that this is a super marginal use case ... I suspect the 5 blokes on this card are the only people that will ever come across it. |
Given that there are no strong opinions against this approach, and the general consensus is that this is okay, I'm going to accept this. I'll merge it this afternoon. |
@emteknetnz There are new conflicts - can you please resolve those before I merge? |
7a88f91
to
337c6e5
Compare
For anyone looking at this in the future, the conflicts mentioned above came from an alternative approach to resolving the same problem - see 511b3bb#diff-9b2f2c197e0cd13a273016f609eebbf671ae5db75396ae73cba64635dd7b75ba |
Issue #10250
PHP 8.1 change the default behaviour of failed mysql statements from 'return false' to 'throw new mysqli_sql_exception()` https://php.watch/versions/8.1/mysqli-error-mode
Travis install failure on the
--prefer-lowest
job will be fixed by silverstripe/silverstripe-travis-shared#36