Skip to content

Comments

Refactor GD2 availability check to use GD_MAJOR_VERSION#19820

Merged
MauricioFauth merged 3 commits intophpmyadmin:masterfrom
LuckyFellow:feature/gd2-detection
Aug 25, 2025
Merged

Refactor GD2 availability check to use GD_MAJOR_VERSION#19820
MauricioFauth merged 3 commits intophpmyadmin:masterfrom
LuckyFellow:feature/gd2-detection

Conversation

@LuckyFellow
Copy link
Contributor

Description

This refactors the GD2 availability detection to use the GD_MAJOR_VERSION constant
(available since PHP 5.2.4) instead of fragile checks with imagecreatetruecolor,
gd_info, or parsing phpinfo output.

The previous implementation could lead to:

  • false positives (e.g. matching "2." in "3.2.0")
  • false negatives (e.g. missing "3.0.0")

With this change, both implementation and PHPUnit tests now rely on
GD_MAJOR_VERSION as the single source of truth, ensuring precise detection
and simplifying the code.

Before submitting pull request, please review the following checklist:

  • Make sure you have read our CONTRIBUTING.md document.
  • Make sure you are making a pull request against the correct branch. For example, for bug fixes in a released version use the corresponding QA branch and for new features use the master branch. If you have a doubt, you can ask as a comment in the bug report or on the mailing list.
  • Every commit has proper Signed-off-by line as described in our DCO. This ensures that the work you're submitting is your own creation.
  • Every commit has a descriptive commit message.
  • Every commit is needed on its own, if you have just minor fixes to previous commits, you can squash them.
  • Any new functionality is covered by tests.

Replaced fragile checks (`imagecreatetruecolor`, `gd_info`, phpinfo parsing)
with the GD_MAJOR_VERSION constant (available since PHP 5.2.4). This avoids
false positives (e.g. matching "2." in "3.2.0") and false negatives
(e.g. missing "3.0.0"), making detection precise.

Updated PHPUnit tests accordingly.

Signed-off-by: Hendrik Becker <[email protected]>
Copy link
Member

@williamdes williamdes left a comment

Choose a reason for hiding this comment

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

It's probably worth sending this to QA_5_2 too

@LuckyFellow
Copy link
Contributor Author

The code in master has been refactored, so this can’t be cherry-picked. I can prepare a backport for QA_5_2 if that’s desired.

@williamdes
Copy link
Member

The code in master has been refactored, so this can’t be cherry-picked. I can prepare a backport for QA_5_2 if that’s desired.

Sure, if there is no particular risks please do a backport

- Replace constant('GD_MAJOR_VERSION') >= 2 with runtime lookup to prevent PHPStan’s “2 >= 2 always true”.
- Remove redundant defined('GD_MAJOR_VERSION') branch; behavior unchanged (?? 0 covers missing constant).

Signed-off-by: Hendrik Becker <[email protected]>
LuckyFellow added a commit to LuckyFellow/phpmyadmin that referenced this pull request Aug 23, 2025
Adapted from phpmyadmin#19820; replaces legacy checks,
updates test, no functional change beyond precise version detection.

Signed-off-by: Hendrik Becker <[email protected]>
@LuckyFellow
Copy link
Contributor Author

CI failures look unrelated to these changes

@MauricioFauth MauricioFauth merged commit 548c5f3 into phpmyadmin:master Aug 25, 2025
1 check passed
@MauricioFauth MauricioFauth self-assigned this Aug 25, 2025
@MauricioFauth MauricioFauth added this to the 6.0.0 milestone Aug 25, 2025
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.

3 participants