Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #11742
Closed
Open
Issue created Feb 28, 2022 by Administrator@rootContributor

[REQ][PHP] PHP 8.1 Support

Created by: satackey

Is your feature request related to a problem? Please describe.

When I used the generated PHP code with PHP 8.1, I got the following Deprecation notice.

Deprecated: Return type of OpenAPI\Client\Model\FooObject::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/php/lib/Model/FooObject.php on line 238

This problem is caused by the following PHP 8.1 incompatible changes, as the generated model classes implement the PHP internal interfaces ArrayAccess and JsonSerializable.

Return Type Compatibility with Internal Classes ¶

Most non-final internal methods now require overriding methods to declare a compatible return type, otherwise a deprecated notice is emitted during inheritance validation. In case the return type cannot be declared for an overriding method due to PHP cross-version compatibility concerns, a #[ReturnTypeWillChange] attribute can be added to silence the deprecation notice. PHP: Backward Incompatible Changes - Manual

Describe the solution you'd like

Add a type hint or #[\ReturnTypeWillChange] attribute to the methods in the template. I'm going to create a pull request with this fix applied.

Describe alternatives you've considered

I'm using a customized template copied from this repository.

Additional context

I have created a repository for reproduction at https://github.com/satackey/openapi-generator-php81 You can reproduce the problem with the following script.

$ git clone https://github.com/satackey/openapi-generator-php81.git
$ docker run --rm -it -v $PWD:/app -w /app openapitools/openapi-generator-cli:latest generate -i ./openapi.yml -o ./ -g php
$ docker run --rm -it -v $PWD:/app -w /app composer install
$ docker run --rm -it -v $PWD:/app -w /app php:8.1 php index.php
Deprecated: Return type of OpenAPI\Client\Model\FooObject::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/lib/Model/FooObject.php on line 238

Deprecated: Return type of OpenAPI\Client\Model\FooObject::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/lib/Model/FooObject.php on line 250

Deprecated: Return type of OpenAPI\Client\Model\FooObject::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/lib/Model/FooObject.php on line 263

Deprecated: Return type of OpenAPI\Client\Model\FooObject::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/lib/Model/FooObject.php on line 279

Deprecated: Return type of OpenAPI\Client\Model\FooObject::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /app/lib/Model/FooObject.php on line 291
Assignee
Assign to
Time tracking