skip to Main Content

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

  1. Can anyone tell me what is wrong here?
  2. 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


  1. Install phpstan and run it through you code with level 0. It will catch and list all syntax errors.

    Install the Package

    composer require --dev phpstan/phpstan
    

    Run

    vendor/bin/phpstan analyse -l 0 {path/to/your/code}
    

    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.

    Login or Signup to reply.
  2. 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:

    error_reporting(?int $error_level = null): int
    

    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:

    error_reporting(E_ALL);
    

    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):

    ini_set('display_errors', 1);
    

    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:

    How do I find deprecated code…?

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search