Skip to content
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 Deprecated: Return type of Requests_* on 8.1 with PHPStan #41

Closed
Mte90 opened this issue Jul 20, 2022 · 13 comments
Closed

PHP Deprecated: Return type of Requests_* on 8.1 with PHPStan #41

Mte90 opened this issue Jul 20, 2022 · 13 comments

Comments

@Mte90
Copy link

Mte90 commented Jul 20, 2022

PHP Deprecated:  Return type of Requests_Utility_FilteredIterator::unserialize($serialized) should either be compatible with ArrayIterator::unserialize(string $data): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21682
Deprecated: Return type of Requests_Utility_FilteredIterator::unserialize($serialized) should either be compatible with ArrayIterator::unserialize(string $data): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21682
PHP Deprecated:  Return type of Requests_Utility_FilteredIterator::__unserialize($serialized) should either be compatible with ArrayIterator::__unserialize(array $data): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21690
Deprecated: Return type of Requests_Utility_FilteredIterator::__unserialize($serialized) should either be compatible with ArrayIterator::__unserialize(array $data): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21690
PHP Deprecated:  Return type of Requests_Utility_FilteredIterator::current() should either be compatible with ArrayIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21676
Deprecated: Return type of Requests_Utility_FilteredIterator::current() should either be compatible with ArrayIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21676
PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18918
Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18918
PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18927
Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18927
PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetSet($key, $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 /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18938
Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $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 /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18938
PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18946
Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18946
PHP Deprecated:  Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18954
Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18954
PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20909
Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20909
PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20918
Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20918
PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $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 /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20929
Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $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 /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20929
PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20937
Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20937
PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20945
Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/www/VVV/www/woocommerce/public_html/wp-content/plugins/plugin/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20945

With PHP 8.1 I am getting all those warning. I know that WP itself doesn't support that version but they are very annoying so I wasn't sure if it was to fix there instead on the phpstan-wordpress package.

Maybe it is possible to add #[\ReturnTypeWillChange] comment on the stubs for those methods so this error is silenced until WP support that version.

@szepeviktor
Copy link
Member

szepeviktor commented Jul 20, 2022

With PHP 8.1

Hello Daniele!
Thank you for your report.

Here are a few statements for you.

  1. WordPress core is not fully PHP 8.1 compatible
  2. The current WordPress ecosystem is not PHP 8.0 compatible
  3. WordPress installations live happily on PHP 7.4 as of 2022

Maybe it is possible to add

This is an automatically generated repo.
If you have a small script or something to fix it please tell me about it now!

@Mte90
Copy link
Author

Mte90 commented Jul 20, 2022

I was thinking of a bash script with sed that will look for the comment (for all of these functions) that will replace adding that comment.
If it is fine I will try to do it :-)

@Mte90
Copy link
Author

Mte90 commented Jul 20, 2022

#!/usr/bin/env bash

function append_flag() {
    lines=$(awk "/$1/{print FNR}" ./wordpress-stubs.php)
    i=0
    for line in $lines
    do
        echo "Found line $line"
        line=$((line+i))
        if ! [ -z "$2" ]; then
            line=$((line+$2))
        fi
        sed -i $line"i         #[\\ReturnTypeWillChange]" ./wordpress-stubs.php
        echo "Appended to line $line"
        # The line number change after the first insertion
        i=$((i+1))
    done
}

append_flag 'public function unserialize\(\$serialized\)'
append_flag 'public function __unserialize\(\$serialized\)'
append_flag "* Get the current item's value after filtering" 4
append_flag 'public function offsetExists\(\$key\)'
append_flag 'public function offsetGet\(\$key\)'
append_flag 'public function offsetSet\(\$key, \$value\)'
append_flag 'public function offsetUnset\(\$key\)'
append_flag 'public function getIterator\(\)'

This bash script fix the stubs and add the flag on the methods reported and now everything is clean :-)

immagine

The only issue is that is no indentation also if I tried for that but I don't think that is a problem.

Do you want a PR? How I can name the script? compatibility.sh?

@szepeviktor
Copy link
Member

szepeviktor commented Jul 20, 2022

Thank you!

for line in $lines

Do you mean these functions appear more than once?

@Mte90
Copy link
Author

Mte90 commented Jul 20, 2022

Yes there are methods with the same name that have the same issues in the Request library, this way we fix it with a single line

@szepeviktor
Copy link
Member

We should create a file similar to https://github.com/php-stubs/wordpress-stubs/blob/master/functionMap.php
and add code to

public function enterNode(Node $node)

@Mte90
Copy link
Author

Mte90 commented Jul 20, 2022

I don't have time now to convert it in PHP code.

I see that the https://github.com/php-stubs/wordpress-stubs/blob/master/generate.sh#L33 file already do some manipulation by bash so maybe we can add that code there.

@benjaminprojas
Copy link

I'm still seeing this issue in the latest version. I see the PR was closed... Is there a reason the issue is closed?

@benjaminprojas
Copy link

The individual notices I am still seeing:

PHP Deprecated:  Return type of Requests_Utility_FilteredIterator::unserialize($serialized) should either be compatible with ArrayIterator::unserialize(string $data): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21682

PHP Deprecated:  Return type of Requests_Utility_FilteredIterator::__unserialize($serialized) should either be compatible with ArrayIterator::__unserialize(array $data): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21690

PHP Deprecated:  Return type of Requests_Utility_FilteredIterator::current() should either be compatible with ArrayIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 21676

PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18918

PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18927

PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetSet($key, $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 /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18938

PHP Deprecated:  Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18946

PHP Deprecated:  Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18954

PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20909

PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20918

PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $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 /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20929

PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20937

PHP Deprecated:  Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 20945

PHP Deprecated:  Optional parameter $id declared before required parameter $object is implicitly treated as a required parameter in /vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php on line 72705

@szepeviktor
Copy link
Member

szepeviktor commented Sep 14, 2022

Hello Benjamin! 👋🏻
The root cause is: WordPress ecosystem does not support PHP 8 (8.0, 8.1 ...) yet.
So an average WordPress installation will not run on e.g. PHP 8.1
I consider PHP 7.4 as of 2022.

These problems have been fixed a year ago in the next release of Requests: WordPress/Requests#505
WordPress core simple hasn't upgraded to that version.

Feel free to send a PR that completes that closed PR.

@szepeviktor
Copy link
Member

szepeviktor commented Sep 14, 2022

Although I suggest you to ignore these in a human way (by not looking at your screen) as PHPStan cannot ignore deprecations.

@janw-me
Copy link
Contributor

janw-me commented Sep 30, 2022

Fixed in #53

@szepeviktor szepeviktor unpinned this issue Sep 30, 2022
@benjaminprojas
Copy link

benjaminprojas commented Oct 29, 2022

Manually including the latest version of the wordpress-stubs fixed most of the errors (thanks @janw-me!). The only one remaining is coming from woocommerce-stubs (issue created here: php-stubs/woocommerce-stubs#16).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants