Skip to content

Commit 48780e2

Browse files
bug #515 Fix constants being redefined in PHP 8.4 polyfill (cs278)
This PR was squashed before being merged into the 1.x branch. Discussion ---------- Fix constants being redefined in PHP 8.4 polyfill Tracked down this error to this library: ``` In bootstrap.php line 19: [ErrorException] Constant CURL_HTTP_VERSION_3 already defined ``` It appears to me the standard is to conditionally define symbols so these two were missing a check. I've also added a basic test which should prevent this happening again. Commits ------- 230379b Fix constants being redefined in PHP 8.4 polyfill
2 parents 7e99e0c + 230379b commit 48780e2

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/Php84/bootstrap.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
}
1717

1818
if (defined('CURL_VERSION_HTTP3') || PHP_VERSION_ID < 80200 && function_exists('curl_version') && curl_version()['version'] >= 0x074200) { // libcurl >= 7.66.0
19-
define('CURL_HTTP_VERSION_3', 30);
19+
if (!defined('CURL_HTTP_VERSION_3')) {
20+
define('CURL_HTTP_VERSION_3', 30);
21+
}
2022

21-
if (defined('CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256')) { // libcurl >= 7.80.0 (7.88 would be better but is slow to check)
23+
if (!defined('CURL_HTTP_VERSION_3ONLY') && defined('CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256')) { // libcurl >= 7.80.0 (7.88 would be better but is slow to check)
2224
define('CURL_HTTP_VERSION_3ONLY', 31);
2325
}
2426
}

tests/BootstrapTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Polyfill\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
16+
class BootstrapTest extends TestCase
17+
{
18+
/**
19+
* Test including the PHP polyfills does not try to redefine any symbols.
20+
*/
21+
public function testIncludingTwice()
22+
{
23+
$this->expectNotToPerformAssertions();
24+
25+
// File should already be loaded once by Composer.
26+
require __DIR__.'/../src/bootstrap.php';
27+
}
28+
}

0 commit comments

Comments
 (0)