Skip to content

Commit ab543f3

Browse files
mskayaliclaude
andcommitted
feat: Add support for PHP 8.4 and 8.5
The SDK cannot be installed on PHP 8.4 or 8.5 because composer.json pins `"php": ">=8.1 <8.4"`. Three deprecations also surface on those versions. 1. `ParseException::__construct()` declared `Exception $previous = null`. Implicitly nullable parameters are deprecated as of PHP 8.4. 2. `ParseStream::getFileContents()` read the locally scoped `$http_response_header`, deprecated as of PHP 8.5 in favour of `http_get_last_response_headers()`. 3. `ParseCurl::close()` called `curl_close()`, deprecated as of PHP 8.5 because it has had no effect since PHP 8.0. The legacy header read is null coalesced on purpose. On PHP 8.5 a direct read of `$http_response_header` raises the deprecation at compile time, so it fires even when the branch never runs, and even inside `isset()`. Four patterns measured on 8.5.8 and 8.5.12: isset($http_response_header) ? $http_response_header : [] deprecation $http_response_header deprecation $http_response_header ?? [] none get_defined_vars()['http_response_header'] ?? [] none A `function_exists()` guard alone is therefore not sufficient. Verification: all 42 files under src/ pass `php -l` with `error_reporting=E_ALL` on PHP 8.5, and a live request through the patched `getFileContents()` returns the response headers on 8.3.32, 8.4.26, 8.5.8 and 8.5.12, with `HTTP/1.1 200 OK` as the first entry. The upper bound follows #520, which moved to `<8.4` when 8.3 landed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 4b52492 commit ab543f3

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
strategy:
2828
matrix:
2929
include:
30+
- name: PHP 8.5
31+
PHP_VERSION: 8.5
32+
- name: PHP 8.4
33+
PHP_VERSION: 8.4
3034
- name: PHP 8.3
3135
PHP_VERSION: 8.3
3236
- name: PHP 8.2

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=8.1 <8.4",
15+
"php": ">=8.1 <8.6",
1616
"ext-curl": "*",
1717
"ext-json": "*"
1818
},

‎src/Parse/HttpClients/ParseCurl.php‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ public function close()
133133
throw new ParseException('You must call ParseCurl::init first');
134134
}
135135

136-
// close our handle
137-
curl_close($this->curl);
138-
139-
// unset our curl handle
136+
// PHP 8.5 deprecates curl_close(); it has had no effect since PHP
137+
// 8.0, when CurlHandle became an object released on last reference.
138+
// Unsetting the handle below is what actually closes it.
140139
$this->curl = null;
141140
}
142141
}

‎src/Parse/HttpClients/ParseStream.php‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,22 @@ public function getErrorCode()
110110
public function getFileContents($filename, $use_include_path, $context)
111111
{
112112
$result = file_get_contents($filename, $use_include_path, $context);
113-
$this->responseHeaders = $http_response_header;
113+
114+
// PHP 8.5 deprecated the locally scoped `$http_response_header`
115+
// variable in favour of `http_get_last_response_headers()`. That
116+
// function does not exist before 8.5, so both paths are kept.
117+
//
118+
// The legacy read uses `??` deliberately: a direct read raises the
119+
// deprecation at compile time on 8.5, even inside `isset()`, while
120+
// a null coalesced read does not.
121+
$hasHeaderFunction = \function_exists(
122+
'http_get_last_response_headers'
123+
);
124+
125+
$this->responseHeaders = $hasHeaderFunction
126+
? (http_get_last_response_headers() ?? [])
127+
: ($http_response_header ?? []);
128+
114129
return $result;
115130
}
116131
}

‎src/Parse/ParseException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ParseException extends Exception
2222
* @param int $code Error code.
2323
* @param \Exception $previous Previous Exception.
2424
*/
25-
public function __construct($message, $code = 0, Exception $previous = null)
25+
public function __construct($message, $code = 0, ?Exception $previous = null)
2626
{
2727
parent::__construct($message, $code, $previous);
2828
}

0 commit comments

Comments
 (0)