Skip to content

Fix: Resolve PHP 8.4 deprecation warnings breaking SVG rendering on Vercel#920

Open
prashanth-kumar-g wants to merge 9 commits into
DenverCoder1:vercelfrom
prashanth-kumar-g:vercel
Open

Fix: Resolve PHP 8.4 deprecation warnings breaking SVG rendering on Vercel#920
prashanth-kumar-g wants to merge 9 commits into
DenverCoder1:vercelfrom
prashanth-kumar-g:vercel

Conversation

@prashanth-kumar-g

@prashanth-kumar-g prashanth-kumar-g commented Jul 14, 2026

Copy link
Copy Markdown

Description

Currently, when deploying this repository on Vercel (which now uses PHP 8.4), the code triggers some PHP deprecation warnings. Because these text warnings are printed before the SVG image data, the response is no longer considered a valid image. As a result, when this streak card is added to a GitHub profile, GitHub's Camo proxy rejects it and the image is not shown.

I have updated the code in api/index.php and api/card.php (or the respective files) to be fully compatible with PHP 8.4. This clears all the warnings and ensures the SVG image loads perfectly on GitHub profiles again.

Type of change

  • Bug fix (added a non-breaking change which fixes an issue)
  • New feature (added a non-breaking change which adds functionality)
  • Updated documentation (updated the readme, templates, or other repo files)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

I deployed the updated code on my own Vercel account and tested the streak card URL directly in the browser to ensure no warnings were showing. I also successfully added the URL to my GitHub profile README.md to confirm the image is visible.

  • Tested locally with a valid username
  • Tested locally with an invalid username
  • Ran tests with composer test
  • Added or updated test cases to test new features

Checklist:

  • I have checked to make sure no other pull requests are open for this issue
  • The code is properly formatted and is consistent with the existing code style
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Screenshots

Before (PHP 8.4 Deprecation Warnings visible before SVG rendering):
Screenshot (430)

After (Clean SVG response rendering perfectly):
Screenshot (431)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent PHP 8.4 deprecation output from corrupting the SVG/PNG response when deployed on Vercel, so GitHub’s image proxy (Camo) accepts and displays the streak card again.

Changes:

  • Added global error suppression / output buffering at the entrypoint to avoid warnings being emitted before SVG output.
  • Updated some nullable parameter typing (NULLnull, ?array) for PHP 8.4 compatibility.
  • Large rewrite of api/cache.php, including moving/duplicating card rendering/output logic.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
api/index.php Adds error suppression/output buffering and keeps response headers / request handling.
api/card.php Adds error suppression and adjusts nullable parameter typing in docblocks/signatures.
api/cache.php Replaces prior cache implementation with rendering/output helpers (and duplicates renderer functions).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/index.php
Comment on lines 1 to 9
<?php
// Turn off all error reporting completely
error_reporting(0);
ini_set('display_errors', '0');

// Start output buffering to capture any accidental output
ob_start();

declare(strict_types=1);
Comment thread api/card.php
Comment on lines 1 to 5
<?php
error_reporting(0);

declare(strict_types=1);

Comment thread api/cache.php
Comment on lines 1 to 6
<?php
error_reporting(0);
ini_set('display_errors', '0');

declare(strict_types=1);

Comment thread api/cache.php
Comment on lines +121 to +127
function getRequestedTheme(array $params): array
{
$key = getCacheKey($user, $options);
$filePath = getCacheFilePath($key);
/**
* @var array<string,array<string,string>> $THEMES
* List of theme names mapped to labeled colors
*/
$THEMES = include "themes.php";
Comment thread api/cache.php
Comment on lines +370 to +374
* @throws InvalidArgumentException If a locale does not exist
*/
// skipcq: PHP-R1006
function generateCard(array $stats, ?array $params = null): string
{
Comment thread api/cache.php
Comment on lines +874 to 882
function renderOutput(string|array $output, int $responseCode = 200): void
{
$response = generateOutput($output, null, $responseCode);
// Always return HTTP 200 for SVG/PNG so GitHub's image proxy (Camo) displays error cards
// instead of broken images. The original error code is included in JSON responses.
http_response_code(200);
header("Content-Type: {$response["contentType"]}");
exit($response["body"]);
}
Comment thread api/index.php
Comment on lines 9 to 10
declare(strict_types=1);

Comment thread api/index.php
Comment on lines 30 to 33
// set cache to refresh once per day (24 hours)
// skipcq: PHP-W1038
$cacheSeconds = CACHE_DURATION;
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $cacheSeconds) . " GMT");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants