Fix: Resolve PHP 8.4 deprecation warnings breaking SVG rendering on Vercel#920
Open
prashanth-kumar-g wants to merge 9 commits into
Open
Fix: Resolve PHP 8.4 deprecation warnings breaking SVG rendering on Vercel#920prashanth-kumar-g wants to merge 9 commits into
prashanth-kumar-g wants to merge 9 commits into
Conversation
Contributor
There was a problem hiding this comment.
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 (
NULL→null,?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 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 on lines
1
to
5
| <?php | ||
| error_reporting(0); | ||
|
|
||
| declare(strict_types=1); | ||
|
|
Comment on lines
1
to
6
| <?php | ||
| error_reporting(0); | ||
| ini_set('display_errors', '0'); | ||
|
|
||
| declare(strict_types=1); | ||
|
|
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 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 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 on lines
9
to
10
| declare(strict_types=1); | ||
|
|
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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.phpandapi/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
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.mdto confirm the image is visible.composer testChecklist:
Screenshots
Before (PHP 8.4 Deprecation Warnings visible before SVG rendering):

After (Clean SVG response rendering perfectly):
