I upgraded to php 8.2 from 7.4 (tried 8.0 after as well but same issue)
I get a 500 error and my host won’t allow me to revert back to 7.4 now so I need to figure this out but I have no idea how I am supposed to investigate this if I can’t get info from console on what is wrong
- Can anyone tell me what is wrong here?
- How do you go about troubleshooting your code for upgrades like this?
<?php
error_reporting(?int $error_level = null): int
include '../functions.php';
$cardsquery = $conn->prepare("SELECT * FROM pf_cards");
$cardsquery->bind_param("ss", $season, $set);
$cardsquery->execute();
$cardsresult = $cardsquery->get_result();
$card_data = [];
while ($pfcards = $cardsresult->fetch_assoc()) {
// Extract and format data as needed
$card = [
'card_image' => $pfcards['card_image'],
'season' => $pfcards['season'],
'card_set' => $pfcards['card_set'],
'pocketfur_cn' => $pfcards['pocketfur_cn'],
'set_number' => $pfcards['set_number'],
'rarity' => $pfcards['rarity'],
'card_cn' => $pfcards['card_cn'],
];
$card_data[] = $card;
}
// Output the data as JSON
header('Content-Type: application/json');
echo json_encode($card_data);
?>
I tried searching different parts of the code on php official site but there is nowhere on the pages that says if its only supported in 8.2 or if its changed. And the upgrade article for 7.4 to either version doesn’t help either, maybe I’m just looking in the wrong place.
2
Answers
Install phpstan and run it through you code with level 0. It will catch and list all syntax errors.
Install the Package
Run
Learn more about phpstan here:
https://phpstan.org/user-guide/getting-started and you can watch a video explaining the usage here https://www.youtube.com/watch?v=zfAuis9LjIA
I also recommend using an IDE, like PHPStorm to better support PHP syntax.
Any hosting service worth using will have somewhere you can access the PHP error logs. If you’ve got a fatal error in your code, there will always be something in those logs, so go straight there. (I’m sure people will suggest exceptions to that rule, but it’s true often enough to be worth assuming.)
If you had done that, you would have found that there is a syntax error on the very first line, where you’ve tried to change a setting:
What you’ve copied there isn’t an example of how to use the function, it’s a description of the function.
What you were probably trying to do was this:
What that will do is add messages for non-fatal problems to wherever the errors are already being logged or displayed. If what you actually wanted was to display the errors – which is only needed if you can’t find the log file – you need this line instead (or as well):
Note that if PHP doesn’t even get to those lines, they’ll have no effect, which is why it’s so important to know where your log file is anyway.
Finally, a clarification:
It’s good to understand that "deprecated" means planned for removal or change in the future. Deprecated code is not code that is going to break anything right now, it is code that you are being given plenty of time to fix. In PHP’s case, any deprecation in an 8.x release means removal / change in version 9.0 at the earliest.
If your site is actually failing to load, what you’re looking for is things that have already been changed or removed. Look for the section in the manual and blog articles marked "non-bacwards compatible changes", and look in your log files for errors.
Logging warnings as well may sometimes help you track down why an error is happening, but it’s important to focus on the right place.