-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP 8.1 compatibility fixes #400
Open
zozlak
wants to merge
11
commits into
easyrdf:main
Choose a base branch
from
zozlak:php8.1
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
* change all PHPUnit `assertContains($expected, $tested)` calls to `assertStringContainsString($expected, $tested)` for PHPUnit 8 and 9 compatibility * test for the `get_magic_quotes_gpc()` existence before calling it as it has been dropped in PHP 8.0 * change the `dbc:Member_states_of_the_United_Nations` to the dbc:Current_member_states_of_the_United_Nations in dbpedia examples and their tests to follow the current dbpedia content * explicitly set flags in `htmlspecialchars()` calls to the `ENT_COMPAT` to assure same behavior accross various PHP versions (default value has been changed in PHP 8.1)
Set phpstan's anlysis level to 3 as it already catches the PHP 8.1 no-goes and going above it generates too many warnings to fix them.
…running under PHP 8.1 Backward-incompatible API changes: * Assure `offsetSet()` and `offsetUnset()` methods implementing the `ArrayAccess` interface don't return any value as those methods should return `void`. See https://www.php.net/manual/en/arrayaccess.offsetset.php and https://www.php.net/manual/en/arrayaccess.offsetunset.php Affected classes: `EasyRdf\Collection`, `EasyRdf\Container`, `EasyRdf\Graph` Other changes: * Make the `EasyRdf\Parser\Arc` and the `EasyRdf\Parser\Json)` inherit directly from the `EasyRdf\Parser` instead of `EasyRdf\Parser\RdfPhp`. Similarly make the `EasyRdf\Serialiser\Arc` and `EasyRdf\Serialiser\Json` inherit directly from the `EasyRdf\Serialiser` instead of the `EasyRdf\Serialiser\RdfPhp`. These changes were required to fix the variadic return type of the `parse()`/`serialize()` methods. In the proper object model the child class can make the return type only narrower and `string` return type of the ARC/JSON parser/serialiser is not a subtype of the `array` type returned by the `RdfPhp` parser/serialiser classes. As the ARC/JSON parser/serialiser don't access any private/protected RdfPhp parser/serialiser properties, they can simply instantiate when needed instead of extening its class. * Add missing `void`, `int` and `bool` return types for methods implementing the `ArrayAccess` interface. * Mark methods implementing the ArrayAccess interface which should have the `mixed` return type with the `#[\ReturnTypeWillChange]` attribute and assure they have a `@return mixed` docstring. The `mixed` type hint can't be used as we want to keep PHP 7 compatibility. * Add explicit `return null` statements for methods implicitly returning null as implicit null return is not compatible with PHP 8.1 * Assure all methods which may return null indicate it in the docstring's `@return` attribute * Add undeclared class property definitions: * `Http\Response::$version` * `Parser\RdfXml::$xmlParser` * Fix the `Http\Client::$rawPostData` initialization and handling (`string` type doesn't cover `null` and a property with value `null` tested with `isset()` returns `true` so there should be no initial value, cleaning should be done with the `unset()` and testing for a value with `isset()`; alternatively the property value should be `string|null`, cleaning should be done with assigning `null` and testing for a value with `empty()`) * Add explicit cast to `string` in all places where PHP methods requiring a string value (like the `strlen()`) are called and there is a risk a value can be `null`. * Specify `htmlspecialchars()` flags explicitly to assure same behavior across all PHP versions (the default value has changed in PHP 8.1) * Set the `EasyRdf\Literal::getValue()` `@return` docstring attribute to `mixed` as its subclasses do return various value types * Fix the `EasyRdf\Serialiser::serialise` `@return` docstring attribute to `string|array` as one of its subclasses (`EasyRdf\Serialiser\RdfPhp`) returns an array. * Fix `@return` docstring for the `EasyRdf\Literal\Date::getValue()` * Fix the `@var` typehint in `lib/Serialiser/Turtle.php:313`
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.
This pull request is a systematic approach to the EasyRdf PHP 8.1 compatibility issues. Instead of depending solely on tests, a static code analyzer phpstan has been used to detect all incompatibilities.
As a side effect fixes for other problems reported by the code analyzer have been provided like making docstring type hints in line with the code, resolving broken inheritance of ARC/JSON and RdfPhp serialisers/parsers, declaring few undeclared class properties, etc.
Last but not least examples and example tests have been fixed both for PHP 8.0/8.1 incompatibilities and for changes in the data they rely upon so that
make test
reports no errors nor warnings.It's worth noting the adjustments required for the PHP 8.1 compatibility introduce backward-incompatible API changes.
ArrayAccess
interfaceoffsetSet()
andoffsetUnset()
methods must returnvoid
while in EasyRdf they sometimes returned a value. I don't expect it to affect many users and this behavior hasn't been covered by tests but it means an EasyRdf release incorporating this pull request will require EasyRdf major version bump.