laminas / laminas-stdlib

SPL extensions, array utilities, error handlers, and more
https://docs.laminas.dev/laminas-stdlib/
BSD 3-Clause "New" or "Revised" License
190 stars 40 forks source link

Provide PHP 8.1 support #35

Closed weierophinney closed 3 years ago

weierophinney commented 3 years ago

This patch builds on #34, but uses a different direction for providing full compatibility with PHP 8.1.

Instead of using polyfills, we can use the #[ReturnValueWillChange] attribute on signatures that extend/implement internal class/interface methods (along with importing the ReturnValueWillChange virtual attribute). Recent updates to phpcs allow this to work, and Psalm discovers the annotation and considers it when determining if a signature change poses a compatibility problem.

Additionally, this patch:

Fixes #24

weierophinney commented 3 years ago

@laminas/technical-steering-committee Here's a simpler patch for 8.1 support that should make the transition far easier.

Ocramius commented 3 years ago

:ship:

Thanks for the stellar work, @matbech @weierophinney.

Thanks for the tip on the annotation, @nikic: it turned indeed out to be a simple missing import that was messing with us!

nikic commented 3 years ago

Thanks for the tip on the annotation, @nikic: it turned indeed out to be a simple missing import that was messing with us!

You're not the first one falling into that particular trap... I wonder whether our deprecation message should suggest #[\ReturnTypeWillChange] instead of #[ReturnTypeWillChange]? That's not the preferred style for most people, but at least it's always valid to use in that form.

weierophinney commented 3 years ago

@nikic That would have definitely resolved it for me - it's easy to forget that attributes are resolved via the current namespace, and the fact that I continued to get the deprecation errors even after adding it made me assume it just didn't work. Having the message include the scoping operator makes it clear it's a globally resolved name; I would have had immediate success AND would have likely gone and added the import statement immediately anyways.

nikic commented 3 years ago

I've opened https://github.com/php/php-src/pull/7454 to adjust the deprecation message.