Skip to content

refactor: resolve CURL_HTTP_VERSION_3 through constant() - #10821

Merged
paulbalandan merged 1 commit into
codeigniter4:4.8from
paulbalandan:curl-http3-psalm
Nov 24, 2026
Merged

paulbalandan merged 1 commit into
codeigniter4:4.8from
paulbalandan:curl-http3-psalm

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
Psalm 7 on PHP 8.3 reports UndefinedConstant for CURL_HTTP_VERSION_3 in CURLRequest::setCURLOptions() and in CURLRequestTest. The constant exists only from PHP 8.4, and the code defines it at runtime behind a defined() check, which Psalm doesn't follow. That fails the Psalm job on 4.8 since the HTTP/3 support landed. develop still runs Psalm 6, which doesn't flag it.

CURLRequest now defines the constant whenever it is missing, no longer only for version 3.0, and reads it with constant('CURL_HTTP_VERSION_3'). The test reads it the same way. The option values are unchanged.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added 4.8 PRs that target the `4.8` branch. refactor Pull requests that refactor code labels Nov 24, 2026

@neznaika0 neznaika0 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.

Wouldn’t it be better to add a PHP version check? What’s the point of having a constant if you can’t use it? You can skip the test.

@paulbalandan

Copy link
Copy Markdown
Member Author

The constant is not purely guarded on the PHP version (8.4). It also depends if PHP is built with libcurl 7.66 or later:

CURL_HTTP_VERSION_3

(Added in 7.66.0) This option makes libcurl attempt to use HTTP/3 to the host given in the URL, with fallback to earlier HTTP versions if needed.

define() covers this, but Psalm 7 does not track constants defined by define(). For the test, I'd keep it, since the match is not guarded by PHP version and skipping it would lose coverage for PHP 8.3

@neznaika0

Copy link
Copy Markdown
Contributor

Ok. We could add a check, but right now I can’t check whether the coverage percentage will change. And this depends on the phpunit configuration.

if (PHP_VERSION_ID >= 80400) {
        // @codeCoverageIgnoreStart
       ...

@paulbalandan

Copy link
Copy Markdown
Member Author

Do you want something like:

if (PHP_VERSION_ID >= 80400 && ! defined('CURL_HTTP_VERSION_3')) {
    define('CURL_HTTP_VERSION_3', 30); // @codeCoverageIgnore
}

?

@neznaika0

Copy link
Copy Markdown
Contributor

@paulbalandan

if (PHP_VERSION_ID >= 80400) {
     // @codeCoverageIgnoreStart
    // Use constant here
    echo CURL_HTTP_VERSION_3;
    // @codeCoverageIgnoreEnd
}

I already answered above; that’s not how it works. The static analyzer won’t ignore the code at 8.3 and check it at 8.4.
Your changes are optimal now.

@paulbalandan
paulbalandan merged commit 6a20a77 into codeigniter4:4.8 Nov 24, 2026
52 checks passed
@paulbalandan
paulbalandan deleted the curl-http3-psalm branch November 24, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch. refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants