What are the best practices for updating PHP code to comply with stricter standards in newer versions?

To update PHP code to comply with stricter standards in newer versions, it is important to review and refactor code that may not be compatible with the latest PHP versions. This includes updating deprecated functions, using strict typing, and adhering to coding standards such as PSR-12. Additionally, it is recommended to utilize tools like PHP_CodeSniffer to identify and fix any coding standards violations.

// Before updating PHP code
function get_user_data($user_id){
    $query = "SELECT * FROM users WHERE id = $user_id";
    $result = mysqli_query($query);
    return mysqli_fetch_assoc($result);
}

// After updating PHP code
function get_user_data(int $user_id): array {
    $connection = new mysqli("localhost", "username", "password", "database");
    $stmt = $connection->prepare("SELECT * FROM users WHERE id = ?");
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    $result = $stmt->get_result();
    return $result->fetch_assoc();
}